aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-02-27 19:18:30 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-02-27 19:18:30 -0500
commit8d37a371b6869920e6c40c495c68eabba1ef3909 (patch)
treedad784512b13832f4f5494cfe0791965c6a2b0f6
parentef1a8de8ea004a689b2aa9f5cefcba2b1a0262f2 (diff)
parent7b4884ca8853a638df0eb5d251d80d67777b8b1a (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/brodo/pcmcia-2.6: (49 commits) pcmcia: validate late-added resources pcmcia: allow for extension of resource interval pcmcia: remove useless msleep in ds.c pcmcia: use read_cis_mem return value pcmcia: handle error in serial_cs config calls pcmcia: add locking to pcmcia_{read,write}_cis_mem pcmcia: avoid prod_id memleak pcmcia: avoid sysfs-related lockup for cardbus pcmcia: use state machine for extended requery pcmcia: delay re-scanning and re-querying of PCMCIA bus pcmcia: use pccardd to handle eject, insert, suspend and resume requests pcmcia: use ops_mutex for rsrc_{mgr,nonstatic} locking pcmcia: use mutex for dynid lock pcmcia: assert locking to struct pcmcia_device pcmcia: add locking documentation pcmcia: simplify locking pcmcia: add locking to struct pcmcia_socket->pcmcia_state() pcmcia: protect s->device_count pcmcia: properly lock skt->irq, skt->irq_mask pcmcia: lock ops->set_socket ...
-rw-r--r--Documentation/pcmcia/locking.txt118
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c2
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c6
-rw-r--r--drivers/pcmcia/Kconfig9
-rw-r--r--drivers/pcmcia/Makefile4
-rw-r--r--drivers/pcmcia/at91_cf.c2
-rw-r--r--drivers/pcmcia/bfin_cf_pcmcia.c2
-rw-r--r--drivers/pcmcia/cardbus.c175
-rw-r--r--drivers/pcmcia/cistpl.c606
-rw-r--r--drivers/pcmcia/cs.c312
-rw-r--r--drivers/pcmcia/cs_internal.h89
-rw-r--r--drivers/pcmcia/ds.c333
-rw-r--r--drivers/pcmcia/electra_cf.c2
-rw-r--r--drivers/pcmcia/i82365.h4
-rw-r--r--drivers/pcmcia/m32r_cfc.c2
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c4
-rw-r--r--drivers/pcmcia/o2micro.h45
-rw-r--r--drivers/pcmcia/omap_cf.c2
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c42
-rw-r--r--drivers/pcmcia/pcmcia_resource.c169
-rw-r--r--drivers/pcmcia/rsrc_mgr.c48
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c285
-rw-r--r--drivers/pcmcia/socket_sysfs.c196
-rw-r--r--drivers/pcmcia/yenta_socket.c5
-rw-r--r--drivers/serial/serial_cs.c7
-rw-r--r--include/pcmcia/ds.h2
-rw-r--r--include/pcmcia/ss.h40
27 files changed, 1257 insertions, 1254 deletions
diff --git a/Documentation/pcmcia/locking.txt b/Documentation/pcmcia/locking.txt
new file mode 100644
index 000000000000..68f622bc4064
--- /dev/null
+++ b/Documentation/pcmcia/locking.txt
@@ -0,0 +1,118 @@
1This file explains the locking and exclusion scheme used in the PCCARD
2and PCMCIA subsystems.
3
4
5A) Overview, Locking Hierarchy:
6===============================
7
8pcmcia_socket_list_rwsem - protects only the list of sockets
9- skt_mutex - serializes card insert / ejection
10 - ops_mutex - serializes socket operation
11
12
13B) Exclusion
14============
15
16The following functions and callbacks to struct pcmcia_socket must
17be called with "skt_mutex" held:
18
19 socket_detect_change()
20 send_event()
21 socket_reset()
22 socket_shutdown()
23 socket_setup()
24 socket_remove()
25 socket_insert()
26 socket_early_resume()
27 socket_late_resume()
28 socket_resume()
29 socket_suspend()
30
31 struct pcmcia_callback *callback
32
33The following functions and callbacks to struct pcmcia_socket must
34be called with "ops_mutex" held:
35
36 socket_reset()
37 socket_setup()
38
39 struct pccard_operations *ops
40 struct pccard_resource_ops *resource_ops;
41
42Note that send_event() and struct pcmcia_callback *callback must not be
43called with "ops_mutex" held.
44
45
46C) Protection
47=============
48
491. Global Data:
50---------------
51struct list_head pcmcia_socket_list;
52
53protected by pcmcia_socket_list_rwsem;
54
55
562. Per-Socket Data:
57-------------------
58The resource_ops and their data are protected by ops_mutex.
59
60The "main" struct pcmcia_socket is protected as follows (read-only fields
61or single-use fields not mentioned):
62
63- by pcmcia_socket_list_rwsem:
64 struct list_head socket_list;
65
66- by thread_lock:
67 unsigned int thread_events;
68
69- by skt_mutex:
70 u_int suspended_state;
71 void (*tune_bridge);
72 struct pcmcia_callback *callback;
73 int resume_status;
74
75- by ops_mutex:
76 socket_state_t socket;
77 u_int state;
78 u_short lock_count;
79 pccard_mem_map cis_mem;
80 void __iomem *cis_virt;
81 struct { } irq;
82 io_window_t io[];
83 pccard_mem_map win[];
84 struct list_head cis_cache;
85 size_t fake_cis_len;
86 u8 *fake_cis;
87 u_int irq_mask;
88 void (*zoom_video);
89 int (*power_hook);
90 u8 resource...;
91 struct list_head devices_list;
92 u8 device_count;
93 struct pcmcia_state;
94
95
963. Per PCMCIA-device Data:
97--------------------------
98
99The "main" struct pcmcia_devie is protected as follows (read-only fields
100or single-use fields not mentioned):
101
102
103- by pcmcia_socket->ops_mutex:
104 struct list_head socket_device_list;
105 struct config_t *function_config;
106 u16 _irq:1;
107 u16 _io:1;
108 u16 _win:4;
109 u16 _locked:1;
110 u16 allow_func_id_match:1;
111 u16 suspended:1;
112 u16 _removed:1;
113
114- by the PCMCIA driver:
115 io_req_t io;
116 irq_req_t irq;
117 config_req_t conf;
118 window_handle_t win;
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 2db4c0a29b05..c9bc896d68af 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1047,7 +1047,7 @@ release_io:
1047static ssize_t cmm_write(struct file *filp, const char __user *buf, 1047static ssize_t cmm_write(struct file *filp, const char __user *buf,
1048 size_t count, loff_t *ppos) 1048 size_t count, loff_t *ppos)
1049{ 1049{
1050 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data; 1050 struct cm4000_dev *dev = filp->private_data;
1051 unsigned int iobase = dev->p_dev->io.BasePort1; 1051 unsigned int iobase = dev->p_dev->io.BasePort1;
1052 unsigned short s; 1052 unsigned short s;
1053 unsigned char tmp; 1053 unsigned char tmp;
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 6dd486d2977b..aa57cfd1e3fb 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -453,8 +453,7 @@ static int mhz_mfc_config(struct pcmcia_device *link)
453 453
454 link->conf.Attributes |= CONF_ENABLE_SPKR; 454 link->conf.Attributes |= CONF_ENABLE_SPKR;
455 link->conf.Status = CCSR_AUDIO_ENA; 455 link->conf.Status = CCSR_AUDIO_ENA;
456 link->irq.Attributes = 456 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
457 IRQ_TYPE_DYNAMIC_SHARING;
458 link->io.IOAddrLines = 16; 457 link->io.IOAddrLines = 16;
459 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 458 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
460 link->io.NumPorts2 = 8; 459 link->io.NumPorts2 = 8;
@@ -652,8 +651,7 @@ static int osi_config(struct pcmcia_device *link)
652 651
653 link->conf.Attributes |= CONF_ENABLE_SPKR; 652 link->conf.Attributes |= CONF_ENABLE_SPKR;
654 link->conf.Status = CCSR_AUDIO_ENA; 653 link->conf.Status = CCSR_AUDIO_ENA;
655 link->irq.Attributes = 654 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
656 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
657 link->io.NumPorts1 = 64; 655 link->io.NumPorts1 = 64;
658 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 656 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
659 link->io.NumPorts2 = 8; 657 link->io.NumPorts2 = 8;
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 9f3adbd9f700..e8f35dac2d51 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -84,7 +84,7 @@ config YENTA
84 tristate "CardBus yenta-compatible bridge support" 84 tristate "CardBus yenta-compatible bridge support"
85 depends on PCI 85 depends on PCI
86 select CARDBUS if !EMBEDDED 86 select CARDBUS if !EMBEDDED
87 select PCCARD_NONSTATIC 87 select PCCARD_NONSTATIC if PCMCIA != n
88 ---help--- 88 ---help---
89 This option enables support for CardBus host bridges. Virtually 89 This option enables support for CardBus host bridges. Virtually
90 all modern PCMCIA bridges are CardBus compatible. A "bridge" is 90 all modern PCMCIA bridges are CardBus compatible. A "bridge" is
@@ -161,9 +161,8 @@ config TCIC
161 161
162config PCMCIA_M8XX 162config PCMCIA_M8XX
163 tristate "MPC8xx PCMCIA support" 163 tristate "MPC8xx PCMCIA support"
164 depends on PCMCIA && PPC && 8xx 164 depends on PCCARD && PPC && 8xx
165 select PCCARD_IODYN 165 select PCCARD_IODYN if PCMCIA != n
166 select PCCARD_NONSTATIC
167 help 166 help
168 Say Y here to include support for PowerPC 8xx series PCMCIA 167 Say Y here to include support for PowerPC 8xx series PCMCIA
169 controller. 168 controller.
@@ -238,14 +237,12 @@ config PCMCIA_PROBE
238config M32R_PCC 237config M32R_PCC
239 bool "M32R PCMCIA I/F" 238 bool "M32R PCMCIA I/F"
240 depends on M32R && CHIP_M32700 && PCMCIA 239 depends on M32R && CHIP_M32700 && PCMCIA
241 select PCCARD_NONSTATIC
242 help 240 help
243 Say Y here to use the M32R PCMCIA controller. 241 Say Y here to use the M32R PCMCIA controller.
244 242
245config M32R_CFC 243config M32R_CFC
246 bool "M32R CF I/F Controller" 244 bool "M32R CF I/F Controller"
247 depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT) 245 depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT)
248 select PCCARD_NONSTATIC
249 help 246 help
250 Say Y here to use the M32R CompactFlash controller. 247 Say Y here to use the M32R CompactFlash controller.
251 248
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 83ff802de544..3c83f68c803a 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
5pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o 5pcmcia_core-y += cs.o rsrc_mgr.o socket_sysfs.o
6pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 6pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
7obj-$(CONFIG_PCCARD) += pcmcia_core.o 7obj-$(CONFIG_PCCARD) += pcmcia_core.o
8 8
9pcmcia-y += ds.o pcmcia_resource.o 9pcmcia-y += ds.o pcmcia_resource.o cistpl.o
10pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o 10pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o
11obj-$(CONFIG_PCMCIA) += pcmcia.o 11obj-$(CONFIG_PCMCIA) += pcmcia.o
12 12
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
57static inline int at91_cf_present(struct at91_cf_socket *cf) 55static 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/bfin_cf_pcmcia.c b/drivers/pcmcia/bfin_cf_pcmcia.c
index 300b368605c9..2482ce7ac6dc 100644
--- a/drivers/pcmcia/bfin_cf_pcmcia.c
+++ b/drivers/pcmcia/bfin_cf_pcmcia.c
@@ -205,7 +205,7 @@ static int __devinit bfin_cf_probe(struct platform_device *pdev)
205 dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n"); 205 dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n");
206 206
207 irq = platform_get_irq(pdev, 0); 207 irq = platform_get_irq(pdev, 0);
208 if (!irq) 208 if (irq <= 0)
209 return -EINVAL; 209 return -EINVAL;
210 210
211 cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */ 211 cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index d99f846451a3..ac0686efbf75 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -20,170 +20,12 @@
20 */ 20 */
21 21
22 22
23#include <linux/module.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/string.h> 24#include <linux/module.h>
26#include <linux/slab.h>
27#include <linux/mm.h>
28#include <linux/pci.h> 25#include <linux/pci.h>
29#include <linux/ioport.h>
30#include <linux/io.h>
31#include <asm/irq.h>
32 26
33#include <pcmcia/cs_types.h>
34#include <pcmcia/ss.h> 27#include <pcmcia/ss.h>
35#include <pcmcia/cs.h>
36#include <pcmcia/cistpl.h>
37#include "cs_internal.h"
38
39/*====================================================================*/
40
41/* Offsets in the Expansion ROM Image Header */
42#define ROM_SIGNATURE 0x0000 /* 2 bytes */
43#define ROM_DATA_PTR 0x0018 /* 2 bytes */
44
45/* Offsets in the CardBus PC Card Data Structure */
46#define PCDATA_SIGNATURE 0x0000 /* 4 bytes */
47#define PCDATA_VPD_PTR 0x0008 /* 2 bytes */
48#define PCDATA_LENGTH 0x000a /* 2 bytes */
49#define PCDATA_REVISION 0x000c
50#define PCDATA_IMAGE_SZ 0x0010 /* 2 bytes */
51#define PCDATA_ROM_LEVEL 0x0012 /* 2 bytes */
52#define PCDATA_CODE_TYPE 0x0014
53#define PCDATA_INDICATOR 0x0015
54
55/*=====================================================================
56
57 Expansion ROM's have a special layout, and pointers specify an
58 image number and an offset within that image. xlate_rom_addr()
59 converts an image/offset address to an absolute offset from the
60 ROM's base address.
61
62=====================================================================*/
63
64static 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
91static 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
101static 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
130int 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
173failput:
174 pci_dev_put(dev);
175fail:
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
188static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq) 30static 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 */
218int __ref cb_alloc(struct pcmcia_socket *s) 67int __ref cb_alloc(struct pcmcia_socket *s)
219{ 68{
220 struct pci_bus *bus = s->cb_dev->subordinate; 69 struct pci_bus *bus = s->cb_dev->subordinate;
@@ -249,12 +98,16 @@ int __ref cb_alloc(struct pcmcia_socket *s)
249 return 0; 98 return 0;
250} 99}
251 100
101/**
102 * cb_free() - remove CardBus device
103 * @s: the pcmcia_socket where the CardBus device was located
104 *
105 * cb_free() handles the lowest level PCI device cleanup.
106 */
252void cb_free(struct pcmcia_socket *s) 107void cb_free(struct pcmcia_socket *s)
253{ 108{
254 struct pci_dev *bridge = s->cb_dev; 109 struct pci_dev *bridge = s->cb_dev;
255 110
256 cb_release_cis_mem(s);
257
258 if (bridge) 111 if (bridge)
259 pci_remove_behind_bridge(bridge); 112 pci_remove_behind_bridge(bridge);
260} 113}
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 25b1cd219e37..2f3622dd4b69 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -64,6 +64,7 @@ module_param(cis_width, int, 0444);
64 64
65void release_cis_mem(struct pcmcia_socket *s) 65void release_cis_mem(struct pcmcia_socket *s)
66{ 66{
67 mutex_lock(&s->ops_mutex);
67 if (s->cis_mem.flags & MAP_ACTIVE) { 68 if (s->cis_mem.flags & MAP_ACTIVE) {
68 s->cis_mem.flags &= ~MAP_ACTIVE; 69 s->cis_mem.flags &= ~MAP_ACTIVE;
69 s->ops->set_mem_map(s, &s->cis_mem); 70 s->ops->set_mem_map(s, &s->cis_mem);
@@ -75,13 +76,15 @@ void release_cis_mem(struct pcmcia_socket *s)
75 iounmap(s->cis_virt); 76 iounmap(s->cis_virt);
76 s->cis_virt = NULL; 77 s->cis_virt = NULL;
77 } 78 }
79 mutex_unlock(&s->ops_mutex);
78} 80}
79EXPORT_SYMBOL(release_cis_mem);
80 81
81/* 82/*
82 * Map the card memory at "card_offset" into virtual space. 83 * Map the card memory at "card_offset" into virtual space.
83 * If flags & MAP_ATTRIB, map the attribute space, otherwise 84 * If flags & MAP_ATTRIB, map the attribute space, otherwise
84 * map the memory space. 85 * map the memory space.
86 *
87 * Must be called with ops_mutex held.
85 */ 88 */
86static void __iomem * 89static void __iomem *
87set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) 90set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags)
@@ -140,6 +143,7 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
140 143
141 dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len); 144 dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
142 145
146 mutex_lock(&s->ops_mutex);
143 if (attr & IS_INDIRECT) { 147 if (attr & IS_INDIRECT) {
144 /* Indirect accesses use a bunch of special registers at fixed 148 /* Indirect accesses use a bunch of special registers at fixed
145 locations in common memory */ 149 locations in common memory */
@@ -151,7 +155,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
151 155
152 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); 156 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0));
153 if (!sys) { 157 if (!sys) {
158 dev_dbg(&s->dev, "could not map memory\n");
154 memset(ptr, 0xff, len); 159 memset(ptr, 0xff, len);
160 mutex_unlock(&s->ops_mutex);
155 return -1; 161 return -1;
156 } 162 }
157 163
@@ -165,6 +171,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
165 } else { 171 } else {
166 u_int inc = 1, card_offset, flags; 172 u_int inc = 1, card_offset, flags;
167 173
174 if (addr > CISTPL_MAX_CIS_SIZE)
175 dev_dbg(&s->dev, "attempt to read CIS mem at addr %#x", addr);
176
168 flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); 177 flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0);
169 if (attr) { 178 if (attr) {
170 flags |= MAP_ATTRIB; 179 flags |= MAP_ATTRIB;
@@ -176,7 +185,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
176 while (len) { 185 while (len) {
177 sys = set_cis_map(s, card_offset, flags); 186 sys = set_cis_map(s, card_offset, flags);
178 if (!sys) { 187 if (!sys) {
188 dev_dbg(&s->dev, "could not map memory\n");
179 memset(ptr, 0xff, len); 189 memset(ptr, 0xff, len);
190 mutex_unlock(&s->ops_mutex);
180 return -1; 191 return -1;
181 } 192 }
182 end = sys + s->map_size; 193 end = sys + s->map_size;
@@ -190,12 +201,12 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
190 addr = 0; 201 addr = 0;
191 } 202 }
192 } 203 }
204 mutex_unlock(&s->ops_mutex);
193 dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n", 205 dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n",
194 *(u_char *)(ptr+0), *(u_char *)(ptr+1), 206 *(u_char *)(ptr+0), *(u_char *)(ptr+1),
195 *(u_char *)(ptr+2), *(u_char *)(ptr+3)); 207 *(u_char *)(ptr+2), *(u_char *)(ptr+3));
196 return 0; 208 return 0;
197} 209}
198EXPORT_SYMBOL(pcmcia_read_cis_mem);
199 210
200 211
201void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 212void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
@@ -206,6 +217,7 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
206 217
207 dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len); 218 dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
208 219
220 mutex_lock(&s->ops_mutex);
209 if (attr & IS_INDIRECT) { 221 if (attr & IS_INDIRECT) {
210 /* Indirect accesses use a bunch of special registers at fixed 222 /* Indirect accesses use a bunch of special registers at fixed
211 locations in common memory */ 223 locations in common memory */
@@ -216,8 +228,11 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
216 } 228 }
217 229
218 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); 230 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0));
219 if (!sys) 231 if (!sys) {
232 dev_dbg(&s->dev, "could not map memory\n");
233 mutex_unlock(&s->ops_mutex);
220 return; /* FIXME: Error */ 234 return; /* FIXME: Error */
235 }
221 236
222 writeb(flags, sys+CISREG_ICTRL0); 237 writeb(flags, sys+CISREG_ICTRL0);
223 writeb(addr & 0xff, sys+CISREG_IADDR0); 238 writeb(addr & 0xff, sys+CISREG_IADDR0);
@@ -239,8 +254,11 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
239 card_offset = addr & ~(s->map_size-1); 254 card_offset = addr & ~(s->map_size-1);
240 while (len) { 255 while (len) {
241 sys = set_cis_map(s, card_offset, flags); 256 sys = set_cis_map(s, card_offset, flags);
242 if (!sys) 257 if (!sys) {
258 dev_dbg(&s->dev, "could not map memory\n");
259 mutex_unlock(&s->ops_mutex);
243 return; /* FIXME: error */ 260 return; /* FIXME: error */
261 }
244 262
245 end = sys + s->map_size; 263 end = sys + s->map_size;
246 sys = sys + (addr & (s->map_size-1)); 264 sys = sys + (addr & (s->map_size-1));
@@ -253,8 +271,8 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
253 addr = 0; 271 addr = 0;
254 } 272 }
255 } 273 }
274 mutex_unlock(&s->ops_mutex);
256} 275}
257EXPORT_SYMBOL(pcmcia_write_cis_mem);
258 276
259 277
260/*====================================================================== 278/*======================================================================
@@ -265,32 +283,36 @@ EXPORT_SYMBOL(pcmcia_write_cis_mem);
265 283
266======================================================================*/ 284======================================================================*/
267 285
268static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, 286static int read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
269 size_t len, void *ptr) 287 size_t len, void *ptr)
270{ 288{
271 struct cis_cache_entry *cis; 289 struct cis_cache_entry *cis;
272 int ret; 290 int ret = 0;
273 291
274 if (s->fake_cis) { 292 if (s->state & SOCKET_CARDBUS)
275 if (s->fake_cis_len >= addr+len) 293 return -EINVAL;
276 memcpy(ptr, s->fake_cis+addr, len);
277 else
278 memset(ptr, 0xff, len);
279 return;
280 }
281 294
282 list_for_each_entry(cis, &s->cis_cache, node) { 295 mutex_lock(&s->ops_mutex);
283 if (cis->addr == addr && cis->len == len && cis->attr == attr) { 296 if (s->fake_cis) {
284 memcpy(ptr, cis->cache, len); 297 if (s->fake_cis_len >= addr+len)
285 return; 298 memcpy(ptr, s->fake_cis+addr, len);
299 else {
300 memset(ptr, 0xff, len);
301 ret = -EINVAL;
302 }
303 mutex_unlock(&s->ops_mutex);
304 return ret;
286 } 305 }
287 }
288 306
289#ifdef CONFIG_CARDBUS 307 list_for_each_entry(cis, &s->cis_cache, node) {
290 if (s->state & SOCKET_CARDBUS) 308 if (cis->addr == addr && cis->len == len && cis->attr == attr) {
291 ret = read_cb_mem(s, attr, addr, len, ptr); 309 memcpy(ptr, cis->cache, len);
292 else 310 mutex_unlock(&s->ops_mutex);
293#endif 311 return 0;
312 }
313 }
314 mutex_unlock(&s->ops_mutex);
315
294 ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); 316 ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr);
295 317
296 if (ret == 0) { 318 if (ret == 0) {
@@ -301,9 +323,12 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
301 cis->len = len; 323 cis->len = len;
302 cis->attr = attr; 324 cis->attr = attr;
303 memcpy(cis->cache, ptr, len); 325 memcpy(cis->cache, ptr, len);
326 mutex_lock(&s->ops_mutex);
304 list_add(&cis->node, &s->cis_cache); 327 list_add(&cis->node, &s->cis_cache);
328 mutex_unlock(&s->ops_mutex);
305 } 329 }
306 } 330 }
331 return ret;
307} 332}
308 333
309static void 334static void
@@ -311,32 +336,35 @@ remove_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, u_int len)
311{ 336{
312 struct cis_cache_entry *cis; 337 struct cis_cache_entry *cis;
313 338
339 mutex_lock(&s->ops_mutex);
314 list_for_each_entry(cis, &s->cis_cache, node) 340 list_for_each_entry(cis, &s->cis_cache, node)
315 if (cis->addr == addr && cis->len == len && cis->attr == attr) { 341 if (cis->addr == addr && cis->len == len && cis->attr == attr) {
316 list_del(&cis->node); 342 list_del(&cis->node);
317 kfree(cis); 343 kfree(cis);
318 break; 344 break;
319 } 345 }
346 mutex_unlock(&s->ops_mutex);
320} 347}
321 348
349/**
350 * destroy_cis_cache() - destroy the CIS cache
351 * @s: pcmcia_socket for which CIS cache shall be destroyed
352 *
353 * This destroys the CIS cache but keeps any fake CIS alive. Must be
354 * called with ops_mutex held.
355 */
356
322void destroy_cis_cache(struct pcmcia_socket *s) 357void destroy_cis_cache(struct pcmcia_socket *s)
323{ 358{
324 struct list_head *l, *n; 359 struct list_head *l, *n;
360 struct cis_cache_entry *cis;
325 361
326 list_for_each_safe(l, n, &s->cis_cache) { 362 list_for_each_safe(l, n, &s->cis_cache) {
327 struct cis_cache_entry *cis = list_entry(l, struct cis_cache_entry, node); 363 cis = list_entry(l, struct cis_cache_entry, node);
328
329 list_del(&cis->node); 364 list_del(&cis->node);
330 kfree(cis); 365 kfree(cis);
331 } 366 }
332
333 /*
334 * If there was a fake CIS, destroy that as well.
335 */
336 kfree(s->fake_cis);
337 s->fake_cis = NULL;
338} 367}
339EXPORT_SYMBOL(destroy_cis_cache);
340 368
341/*====================================================================== 369/*======================================================================
342 370
@@ -349,6 +377,10 @@ int verify_cis_cache(struct pcmcia_socket *s)
349{ 377{
350 struct cis_cache_entry *cis; 378 struct cis_cache_entry *cis;
351 char *buf; 379 char *buf;
380 int ret;
381
382 if (s->state & SOCKET_CARDBUS)
383 return -EINVAL;
352 384
353 buf = kmalloc(256, GFP_KERNEL); 385 buf = kmalloc(256, GFP_KERNEL);
354 if (buf == NULL) { 386 if (buf == NULL) {
@@ -361,14 +393,9 @@ int verify_cis_cache(struct pcmcia_socket *s)
361 393
362 if (len > 256) 394 if (len > 256)
363 len = 256; 395 len = 256;
364#ifdef CONFIG_CARDBUS
365 if (s->state & SOCKET_CARDBUS)
366 read_cb_mem(s, cis->attr, cis->addr, len, buf);
367 else
368#endif
369 pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
370 396
371 if (memcmp(buf, cis->cache, len) != 0) { 397 ret = pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
398 if (ret || memcmp(buf, cis->cache, len) != 0) {
372 kfree(buf); 399 kfree(buf);
373 return -1; 400 return -1;
374 } 401 }
@@ -391,17 +418,20 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
391 dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); 418 dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n");
392 return -EINVAL; 419 return -EINVAL;
393 } 420 }
421 mutex_lock(&s->ops_mutex);
394 kfree(s->fake_cis); 422 kfree(s->fake_cis);
395 s->fake_cis = kmalloc(len, GFP_KERNEL); 423 s->fake_cis = kmalloc(len, GFP_KERNEL);
396 if (s->fake_cis == NULL) { 424 if (s->fake_cis == NULL) {
397 dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); 425 dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n");
426 mutex_unlock(&s->ops_mutex);
398 return -ENOMEM; 427 return -ENOMEM;
399 } 428 }
400 s->fake_cis_len = len; 429 s->fake_cis_len = len;
401 memcpy(s->fake_cis, data, len); 430 memcpy(s->fake_cis, data, len);
431 dev_info(&s->dev, "Using replacement CIS\n");
432 mutex_unlock(&s->ops_mutex);
402 return 0; 433 return 0;
403} 434}
404EXPORT_SYMBOL(pcmcia_replace_cis);
405 435
406/*====================================================================== 436/*======================================================================
407 437
@@ -425,25 +455,16 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
425{ 455{
426 if (!s) 456 if (!s)
427 return -EINVAL; 457 return -EINVAL;
428 if (!(s->state & SOCKET_PRESENT)) 458
459 if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS))
429 return -ENODEV; 460 return -ENODEV;
430 tuple->TupleLink = tuple->Flags = 0; 461 tuple->TupleLink = tuple->Flags = 0;
431#ifdef CONFIG_CARDBUS 462
432 if (s->state & SOCKET_CARDBUS) { 463 /* Assume presence of a LONGLINK_C to address 0 */
433 struct pci_dev *dev = s->cb_dev; 464 tuple->CISOffset = tuple->LinkOffset = 0;
434 u_int ptr; 465 SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
435 pci_bus_read_config_dword(dev->subordinate, 0, PCI_CARDBUS_CIS, &ptr); 466
436 tuple->CISOffset = ptr & ~7; 467 if ((s->functions > 1) && !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
437 SPACE(tuple->Flags) = (ptr & 7);
438 } else
439#endif
440 {
441 /* Assume presence of a LONGLINK_C to address 0 */
442 tuple->CISOffset = tuple->LinkOffset = 0;
443 SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
444 }
445 if (!(s->state & SOCKET_CARDBUS) && (s->functions > 1) &&
446 !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
447 cisdata_t req = tuple->DesiredTuple; 468 cisdata_t req = tuple->DesiredTuple;
448 tuple->DesiredTuple = CISTPL_LONGLINK_MFC; 469 tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
449 if (pccard_get_next_tuple(s, function, tuple) == 0) { 470 if (pccard_get_next_tuple(s, function, tuple) == 0) {
@@ -456,17 +477,19 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
456 } 477 }
457 return pccard_get_next_tuple(s, function, tuple); 478 return pccard_get_next_tuple(s, function, tuple);
458} 479}
459EXPORT_SYMBOL(pccard_get_first_tuple);
460 480
461static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) 481static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
462{ 482{
463 u_char link[5]; 483 u_char link[5];
464 u_int ofs; 484 u_int ofs;
485 int ret;
465 486
466 if (MFC_FN(tuple->Flags)) { 487 if (MFC_FN(tuple->Flags)) {
467 /* Get indirect link from the MFC tuple */ 488 /* Get indirect link from the MFC tuple */
468 read_cis_cache(s, LINK_SPACE(tuple->Flags), 489 ret = read_cis_cache(s, LINK_SPACE(tuple->Flags),
469 tuple->LinkOffset, 5, link); 490 tuple->LinkOffset, 5, link);
491 if (ret)
492 return -1;
470 ofs = get_unaligned_le32(link + 1); 493 ofs = get_unaligned_le32(link + 1);
471 SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); 494 SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR);
472 /* Move to the next indirect link */ 495 /* Move to the next indirect link */
@@ -479,10 +502,12 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
479 } else { 502 } else {
480 return -1; 503 return -1;
481 } 504 }
482 if (!(s->state & SOCKET_CARDBUS) && SPACE(tuple->Flags)) { 505 if (SPACE(tuple->Flags)) {
483 /* This is ugly, but a common CIS error is to code the long 506 /* This is ugly, but a common CIS error is to code the long
484 link offset incorrectly, so we check the right spot... */ 507 link offset incorrectly, so we check the right spot... */
485 read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); 508 ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link);
509 if (ret)
510 return -1;
486 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && 511 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) &&
487 (strncmp(link+2, "CIS", 3) == 0)) 512 (strncmp(link+2, "CIS", 3) == 0))
488 return ofs; 513 return ofs;
@@ -490,7 +515,9 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
490 /* Then, we try the wrong spot... */ 515 /* Then, we try the wrong spot... */
491 ofs = ofs >> 1; 516 ofs = ofs >> 1;
492 } 517 }
493 read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); 518 ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link);
519 if (ret)
520 return -1;
494 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && 521 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) &&
495 (strncmp(link+2, "CIS", 3) == 0)) 522 (strncmp(link+2, "CIS", 3) == 0))
496 return ofs; 523 return ofs;
@@ -502,10 +529,11 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
502{ 529{
503 u_char link[2], tmp; 530 u_char link[2], tmp;
504 int ofs, i, attr; 531 int ofs, i, attr;
532 int ret;
505 533
506 if (!s) 534 if (!s)
507 return -EINVAL; 535 return -EINVAL;
508 if (!(s->state & SOCKET_PRESENT)) 536 if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS))
509 return -ENODEV; 537 return -ENODEV;
510 538
511 link[1] = tuple->TupleLink; 539 link[1] = tuple->TupleLink;
@@ -516,7 +544,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
516 if (link[1] == 0xff) { 544 if (link[1] == 0xff) {
517 link[0] = CISTPL_END; 545 link[0] = CISTPL_END;
518 } else { 546 } else {
519 read_cis_cache(s, attr, ofs, 2, link); 547 ret = read_cis_cache(s, attr, ofs, 2, link);
548 if (ret)
549 return -1;
520 if (link[0] == CISTPL_NULL) { 550 if (link[0] == CISTPL_NULL) {
521 ofs++; continue; 551 ofs++; continue;
522 } 552 }
@@ -528,7 +558,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
528 if (ofs < 0) 558 if (ofs < 0)
529 return -ENOSPC; 559 return -ENOSPC;
530 attr = SPACE(tuple->Flags); 560 attr = SPACE(tuple->Flags);
531 read_cis_cache(s, attr, ofs, 2, link); 561 ret = read_cis_cache(s, attr, ofs, 2, link);
562 if (ret)
563 return -1;
532 } 564 }
533 565
534 /* Is this a link tuple? Make a note of it */ 566 /* Is this a link tuple? Make a note of it */
@@ -542,12 +574,16 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
542 case CISTPL_LONGLINK_A: 574 case CISTPL_LONGLINK_A:
543 HAS_LINK(tuple->Flags) = 1; 575 HAS_LINK(tuple->Flags) = 1;
544 LINK_SPACE(tuple->Flags) = attr | IS_ATTR; 576 LINK_SPACE(tuple->Flags) = attr | IS_ATTR;
545 read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); 577 ret = read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset);
578 if (ret)
579 return -1;
546 break; 580 break;
547 case CISTPL_LONGLINK_C: 581 case CISTPL_LONGLINK_C:
548 HAS_LINK(tuple->Flags) = 1; 582 HAS_LINK(tuple->Flags) = 1;
549 LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR; 583 LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR;
550 read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); 584 ret = read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset);
585 if (ret)
586 return -1;
551 break; 587 break;
552 case CISTPL_INDIRECT: 588 case CISTPL_INDIRECT:
553 HAS_LINK(tuple->Flags) = 1; 589 HAS_LINK(tuple->Flags) = 1;
@@ -559,7 +595,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
559 LINK_SPACE(tuple->Flags) = attr; 595 LINK_SPACE(tuple->Flags) = attr;
560 if (function == BIND_FN_ALL) { 596 if (function == BIND_FN_ALL) {
561 /* Follow all the MFC links */ 597 /* Follow all the MFC links */
562 read_cis_cache(s, attr, ofs+2, 1, &tmp); 598 ret = read_cis_cache(s, attr, ofs+2, 1, &tmp);
599 if (ret)
600 return -1;
563 MFC_FN(tuple->Flags) = tmp; 601 MFC_FN(tuple->Flags) = tmp;
564 } else { 602 } else {
565 /* Follow exactly one of the links */ 603 /* Follow exactly one of the links */
@@ -592,7 +630,6 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
592 tuple->CISOffset = ofs + 2; 630 tuple->CISOffset = ofs + 2;
593 return 0; 631 return 0;
594} 632}
595EXPORT_SYMBOL(pccard_get_next_tuple);
596 633
597/*====================================================================*/ 634/*====================================================================*/
598 635
@@ -601,6 +638,7 @@ EXPORT_SYMBOL(pccard_get_next_tuple);
601int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) 638int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
602{ 639{
603 u_int len; 640 u_int len;
641 int ret;
604 642
605 if (!s) 643 if (!s)
606 return -EINVAL; 644 return -EINVAL;
@@ -611,12 +649,13 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
611 tuple->TupleDataLen = tuple->TupleLink; 649 tuple->TupleDataLen = tuple->TupleLink;
612 if (len == 0) 650 if (len == 0)
613 return 0; 651 return 0;
614 read_cis_cache(s, SPACE(tuple->Flags), 652 ret = read_cis_cache(s, SPACE(tuple->Flags),
615 tuple->CISOffset + tuple->TupleOffset, 653 tuple->CISOffset + tuple->TupleOffset,
616 _MIN(len, tuple->TupleDataMax), tuple->TupleData); 654 _MIN(len, tuple->TupleDataMax), tuple->TupleData);
655 if (ret)
656 return -1;
617 return 0; 657 return 0;
618} 658}
619EXPORT_SYMBOL(pccard_get_tuple_data);
620 659
621 660
622/*====================================================================== 661/*======================================================================
@@ -1190,119 +1229,6 @@ static int parse_cftable_entry(tuple_t *tuple,
1190 1229
1191/*====================================================================*/ 1230/*====================================================================*/
1192 1231
1193#ifdef CONFIG_CARDBUS
1194
1195static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar)
1196{
1197 u_char *p;
1198 if (tuple->TupleDataLen < 6)
1199 return -EINVAL;
1200 p = (u_char *)tuple->TupleData;
1201 bar->attr = *p;
1202 p += 2;
1203 bar->size = get_unaligned_le32(p);
1204 return 0;
1205}
1206
1207static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
1208{
1209 u_char *p;
1210
1211 p = (u_char *)tuple->TupleData;
1212 if ((*p != 3) || (tuple->TupleDataLen < 6))
1213 return -EINVAL;
1214 config->last_idx = *(++p);
1215 p++;
1216 config->base = get_unaligned_le32(p);
1217 config->subtuples = tuple->TupleDataLen - 6;
1218 return 0;
1219}
1220
1221static int parse_cftable_entry_cb(tuple_t *tuple,
1222 cistpl_cftable_entry_cb_t *entry)
1223{
1224 u_char *p, *q, features;
1225
1226 p = tuple->TupleData;
1227 q = p + tuple->TupleDataLen;
1228 entry->index = *p & 0x3f;
1229 entry->flags = 0;
1230 if (*p & 0x40)
1231 entry->flags |= CISTPL_CFTABLE_DEFAULT;
1232
1233 /* Process optional features */
1234 if (++p == q)
1235 return -EINVAL;
1236 features = *p; p++;
1237
1238 /* Power options */
1239 if ((features & 3) > 0) {
1240 p = parse_power(p, q, &entry->vcc);
1241 if (p == NULL)
1242 return -EINVAL;
1243 } else
1244 entry->vcc.present = 0;
1245 if ((features & 3) > 1) {
1246 p = parse_power(p, q, &entry->vpp1);
1247 if (p == NULL)
1248 return -EINVAL;
1249 } else
1250 entry->vpp1.present = 0;
1251 if ((features & 3) > 2) {
1252 p = parse_power(p, q, &entry->vpp2);
1253 if (p == NULL)
1254 return -EINVAL;
1255 } else
1256 entry->vpp2.present = 0;
1257
1258 /* I/O window options */
1259 if (features & 0x08) {
1260 if (p == q)
1261 return -EINVAL;
1262 entry->io = *p; p++;
1263 } else
1264 entry->io = 0;
1265
1266 /* Interrupt options */
1267 if (features & 0x10) {
1268 p = parse_irq(p, q, &entry->irq);
1269 if (p == NULL)
1270 return -EINVAL;
1271 } else
1272 entry->irq.IRQInfo1 = 0;
1273
1274 if (features & 0x20) {
1275 if (p == q)
1276 return -EINVAL;
1277 entry->mem = *p; p++;
1278 } else
1279 entry->mem = 0;
1280
1281 /* Misc features */
1282 if (features & 0x80) {
1283 if (p == q)
1284 return -EINVAL;
1285 entry->flags |= (*p << 8);
1286 if (*p & 0x80) {
1287 if (++p == q)
1288 return -EINVAL;
1289 entry->flags |= (*p << 16);
1290 }
1291 while (*p & 0x80)
1292 if (++p == q)
1293 return -EINVAL;
1294 p++;
1295 }
1296
1297 entry->subtuples = q-p;
1298
1299 return 0;
1300}
1301
1302#endif
1303
1304/*====================================================================*/
1305
1306static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) 1232static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo)
1307{ 1233{
1308 u_char *p, *q; 1234 u_char *p, *q;
@@ -1404,17 +1330,6 @@ int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse)
1404 case CISTPL_DEVICE_A: 1330 case CISTPL_DEVICE_A:
1405 ret = parse_device(tuple, &parse->device); 1331 ret = parse_device(tuple, &parse->device);
1406 break; 1332 break;
1407#ifdef CONFIG_CARDBUS
1408 case CISTPL_BAR:
1409 ret = parse_bar(tuple, &parse->bar);
1410 break;
1411 case CISTPL_CONFIG_CB:
1412 ret = parse_config_cb(tuple, &parse->config);
1413 break;
1414 case CISTPL_CFTABLE_ENTRY_CB:
1415 ret = parse_cftable_entry_cb(tuple, &parse->cftable_entry_cb);
1416 break;
1417#endif
1418 case CISTPL_CHECKSUM: 1333 case CISTPL_CHECKSUM:
1419 ret = parse_checksum(tuple, &parse->checksum); 1334 ret = parse_checksum(tuple, &parse->checksum);
1420 break; 1335 break;
@@ -1513,7 +1428,6 @@ done:
1513 kfree(buf); 1428 kfree(buf);
1514 return ret; 1429 return ret;
1515} 1430}
1516EXPORT_SYMBOL(pccard_read_tuple);
1517 1431
1518 1432
1519/** 1433/**
@@ -1573,84 +1487,238 @@ next_entry:
1573 kfree(buf); 1487 kfree(buf);
1574 return ret; 1488 return ret;
1575} 1489}
1576EXPORT_SYMBOL(pccard_loop_tuple);
1577 1490
1578 1491
1579/*====================================================================== 1492/**
1580 1493 * pccard_validate_cis() - check whether card has a sensible CIS
1581 This tries to determine if a card has a sensible CIS. It returns 1494 * @s: the struct pcmcia_socket we are to check
1582 the number of tuples in the CIS, or 0 if the CIS looks bad. The 1495 * @info: returns the number of tuples in the (valid) CIS, or 0
1583 checks include making sure several critical tuples are present and 1496 *
1584 valid; seeing if the total number of tuples is reasonable; and 1497 * This tries to determine if a card has a sensible CIS. In @info, it
1585 looking for tuples that use reserved codes. 1498 * returns the number of tuples in the CIS, or 0 if the CIS looks bad. The
1586 1499 * checks include making sure several critical tuples are present and
1587======================================================================*/ 1500 * valid; seeing if the total number of tuples is reasonable; and
1588 1501 * looking for tuples that use reserved codes.
1502 *
1503 * The function returns 0 on success.
1504 */
1589int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) 1505int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
1590{ 1506{
1591 tuple_t *tuple; 1507 tuple_t *tuple;
1592 cisparse_t *p; 1508 cisparse_t *p;
1593 unsigned int count = 0; 1509 unsigned int count = 0;
1594 int ret, reserved, dev_ok = 0, ident_ok = 0; 1510 int ret, reserved, dev_ok = 0, ident_ok = 0;
1595 1511
1596 if (!s) 1512 if (!s)
1597 return -EINVAL; 1513 return -EINVAL;
1598 1514
1599 tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); 1515 /* We do not want to validate the CIS cache... */
1600 if (tuple == NULL) { 1516 mutex_lock(&s->ops_mutex);
1601 dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); 1517 destroy_cis_cache(s);
1602 return -ENOMEM; 1518 mutex_unlock(&s->ops_mutex);
1603 }
1604 p = kmalloc(sizeof(*p), GFP_KERNEL);
1605 if (p == NULL) {
1606 kfree(tuple);
1607 dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n");
1608 return -ENOMEM;
1609 }
1610 1519
1611 count = reserved = 0; 1520 tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
1612 tuple->DesiredTuple = RETURN_FIRST_TUPLE; 1521 if (tuple == NULL) {
1613 tuple->Attributes = TUPLE_RETURN_COMMON; 1522 dev_warn(&s->dev, "no memory to validate CIS\n");
1614 ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple); 1523 return -ENOMEM;
1615 if (ret != 0) 1524 }
1616 goto done; 1525 p = kmalloc(sizeof(*p), GFP_KERNEL);
1617 1526 if (p == NULL) {
1618 /* First tuple should be DEVICE; we should really have either that 1527 kfree(tuple);
1619 or a CFTABLE_ENTRY of some sort */ 1528 dev_warn(&s->dev, "no memory to validate CIS\n");
1620 if ((tuple->TupleCode == CISTPL_DEVICE) || 1529 return -ENOMEM;
1621 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p) == 0) || 1530 }
1622 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p) == 0)) 1531
1623 dev_ok++; 1532 count = reserved = 0;
1624 1533 tuple->DesiredTuple = RETURN_FIRST_TUPLE;
1625 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 1534 tuple->Attributes = TUPLE_RETURN_COMMON;
1626 tuple, for card identification. Certain old D-Link and Linksys 1535 ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple);
1627 cards have only a broken VERS_2 tuple; hence the bogus test. */
1628 if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) ||
1629 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) ||
1630 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC))
1631 ident_ok++;
1632
1633 if (!dev_ok && !ident_ok)
1634 goto done;
1635
1636 for (count = 1; count < MAX_TUPLES; count++) {
1637 ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple);
1638 if (ret != 0) 1536 if (ret != 0)
1639 break; 1537 goto done;
1640 if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || 1538
1641 ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || 1539 /* First tuple should be DEVICE; we should really have either that
1642 ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) 1540 or a CFTABLE_ENTRY of some sort */
1643 reserved++; 1541 if ((tuple->TupleCode == CISTPL_DEVICE) ||
1644 } 1542 (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p)) ||
1645 if ((count == MAX_TUPLES) || (reserved > 5) || 1543 (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p)))
1646 ((!dev_ok || !ident_ok) && (count > 10))) 1544 dev_ok++;
1647 count = 0; 1545
1546 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
1547 tuple, for card identification. Certain old D-Link and Linksys
1548 cards have only a broken VERS_2 tuple; hence the bogus test. */
1549 if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) ||
1550 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) ||
1551 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC))
1552 ident_ok++;
1553
1554 if (!dev_ok && !ident_ok)
1555 goto done;
1556
1557 for (count = 1; count < MAX_TUPLES; count++) {
1558 ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple);
1559 if (ret != 0)
1560 break;
1561 if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
1562 ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) ||
1563 ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
1564 reserved++;
1565 }
1566 if ((count == MAX_TUPLES) || (reserved > 5) ||
1567 ((!dev_ok || !ident_ok) && (count > 10)))
1568 count = 0;
1569
1570 ret = 0;
1648 1571
1649done: 1572done:
1650 if (info) 1573 /* invalidate CIS cache on failure */
1651 *info = count; 1574 if (!dev_ok || !ident_ok || !count) {
1652 kfree(tuple); 1575 mutex_lock(&s->ops_mutex);
1653 kfree(p); 1576 destroy_cis_cache(s);
1654 return 0; 1577 mutex_unlock(&s->ops_mutex);
1578 ret = -EIO;
1579 }
1580
1581 if (info)
1582 *info = count;
1583 kfree(tuple);
1584 kfree(p);
1585 return ret;
1655} 1586}
1656EXPORT_SYMBOL(pccard_validate_cis); 1587
1588
1589#define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
1590
1591static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf,
1592 loff_t off, size_t count)
1593{
1594 tuple_t tuple;
1595 int status, i;
1596 loff_t pointer = 0;
1597 ssize_t ret = 0;
1598 u_char *tuplebuffer;
1599 u_char *tempbuffer;
1600
1601 tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL);
1602 if (!tuplebuffer)
1603 return -ENOMEM;
1604
1605 tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL);
1606 if (!tempbuffer) {
1607 ret = -ENOMEM;
1608 goto free_tuple;
1609 }
1610
1611 memset(&tuple, 0, sizeof(tuple_t));
1612
1613 tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
1614 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
1615 tuple.TupleOffset = 0;
1616
1617 status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple);
1618 while (!status) {
1619 tuple.TupleData = tuplebuffer;
1620 tuple.TupleDataMax = 255;
1621 memset(tuplebuffer, 0, sizeof(u_char) * 255);
1622
1623 status = pccard_get_tuple_data(s, &tuple);
1624 if (status)
1625 break;
1626
1627 if (off < (pointer + 2 + tuple.TupleDataLen)) {
1628 tempbuffer[0] = tuple.TupleCode & 0xff;
1629 tempbuffer[1] = tuple.TupleLink & 0xff;
1630 for (i = 0; i < tuple.TupleDataLen; i++)
1631 tempbuffer[i + 2] = tuplebuffer[i] & 0xff;
1632
1633 for (i = 0; i < (2 + tuple.TupleDataLen); i++) {
1634 if (((i + pointer) >= off) &&
1635 (i + pointer) < (off + count)) {
1636 buf[ret] = tempbuffer[i];
1637 ret++;
1638 }
1639 }
1640 }
1641
1642 pointer += 2 + tuple.TupleDataLen;
1643
1644 if (pointer >= (off + count))
1645 break;
1646
1647 if (tuple.TupleCode == CISTPL_END)
1648 break;
1649 status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple);
1650 }
1651
1652 kfree(tempbuffer);
1653 free_tuple:
1654 kfree(tuplebuffer);
1655
1656 return ret;
1657}
1658
1659
1660static ssize_t pccard_show_cis(struct kobject *kobj,
1661 struct bin_attribute *bin_attr,
1662 char *buf, loff_t off, size_t count)
1663{
1664 unsigned int size = 0x200;
1665
1666 if (off >= size)
1667 count = 0;
1668 else {
1669 struct pcmcia_socket *s;
1670 unsigned int chains;
1671
1672 if (off + count > size)
1673 count = size - off;
1674
1675 s = to_socket(container_of(kobj, struct device, kobj));
1676
1677 if (!(s->state & SOCKET_PRESENT))
1678 return -ENODEV;
1679 if (pccard_validate_cis(s, &chains))
1680 return -EIO;
1681 if (!chains)
1682 return -ENODATA;
1683
1684 count = pccard_extract_cis(s, buf, off, count);
1685 }
1686
1687 return count;
1688}
1689
1690
1691static ssize_t pccard_store_cis(struct kobject *kobj,
1692 struct bin_attribute *bin_attr,
1693 char *buf, loff_t off, size_t count)
1694{
1695 struct pcmcia_socket *s;
1696 int error;
1697
1698 s = to_socket(container_of(kobj, struct device, kobj));
1699
1700 if (off)
1701 return -EINVAL;
1702
1703 if (count >= CISTPL_MAX_CIS_SIZE)
1704 return -EINVAL;
1705
1706 if (!(s->state & SOCKET_PRESENT))
1707 return -ENODEV;
1708
1709 error = pcmcia_replace_cis(s, buf, count);
1710 if (error)
1711 return -EIO;
1712
1713 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
1714
1715 return count;
1716}
1717
1718
1719struct bin_attribute pccard_cis_attr = {
1720 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR },
1721 .size = 0x200,
1722 .read = pccard_show_cis,
1723 .write = pccard_store_cis,
1724};
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 6d6f82b38a68..e679e708db63 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -140,19 +140,13 @@ struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt)
140 struct device *dev = get_device(&skt->dev); 140 struct device *dev = get_device(&skt->dev);
141 if (!dev) 141 if (!dev)
142 return NULL; 142 return NULL;
143 skt = dev_get_drvdata(dev); 143 return dev_get_drvdata(dev);
144 if (!try_module_get(skt->owner)) {
145 put_device(&skt->dev);
146 return NULL;
147 }
148 return skt;
149} 144}
150EXPORT_SYMBOL(pcmcia_get_socket); 145EXPORT_SYMBOL(pcmcia_get_socket);
151 146
152 147
153void pcmcia_put_socket(struct pcmcia_socket *skt) 148void 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}
158EXPORT_SYMBOL(pcmcia_put_socket); 152EXPORT_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 */
297EXPORT_SYMBOL(pcmcia_unregister_socket); 294EXPORT_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
349static 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
356static int socket_reset(struct pcmcia_socket *skt) 346static 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
427static int socket_setup(struct pcmcia_socket *skt, int initial_delay) 429static 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
555static int socket_early_resume(struct pcmcia_socket *skt) 567static 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
565static int socket_late_resume(struct pcmcia_socket *skt) 579static 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 */
733EXPORT_SYMBOL(pcmcia_parse_events); 792EXPORT_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 */
805void 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}
817EXPORT_SYMBOL(pcmcia_parse_uevents);
818
735 819
736/* register pcmcia_callback */ 820/* register pcmcia_callback */
737int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) 821int 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)
812EXPORT_SYMBOL(pcmcia_reset_card); 899EXPORT_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 */
818int 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 */
845EXPORT_SYMBOL(pcmcia_suspend_card);
846
847
848int 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 */
872EXPORT_SYMBOL(pcmcia_resume_card);
873
874
875/* These handle user requests to eject or insert a card. */
876int 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 */
902EXPORT_SYMBOL(pcmcia_eject_card);
903
904
905int 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 */
927EXPORT_SYMBOL(pcmcia_insert_card);
928
929
930static int pcmcia_socket_uevent(struct device *dev, 902static 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
90static 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
102static 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 */
116int verify_cis_cache(struct pcmcia_socket *s);
117
118/* rsrc_mgr.c */
119void release_resource_db(struct pcmcia_socket *s);
120
121/* socket_sysfs.c */ 95/* socket_sysfs.c */
122extern int pccard_sysfs_add_socket(struct device *dev); 96extern int pccard_sysfs_add_socket(struct device *dev);
123extern void pccard_sysfs_remove_socket(struct device *dev); 97extern 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 */
126int cb_alloc(struct pcmcia_socket *s); 100int cb_alloc(struct pcmcia_socket *s);
127void cb_free(struct pcmcia_socket *s); 101void cb_free(struct pcmcia_socket *s);
128int 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;
151int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 124int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
152struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr); 125struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
153 126
154int pcmcia_suspend_card(struct pcmcia_socket *skt); 127void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events);
155int pcmcia_resume_card(struct pcmcia_socket *skt); 128#define PCMCIA_UEVENT_EJECT 0x0001
156 129#define PCMCIA_UEVENT_INSERT 0x0002
157int pcmcia_eject_card(struct pcmcia_socket *skt); 130#define PCMCIA_UEVENT_SUSPEND 0x0004
158int pcmcia_insert_card(struct pcmcia_socket *skt); 131#define PCMCIA_UEVENT_RESUME 0x0008
132#define PCMCIA_UEVENT_REQUERY 0x0010
159 133
160struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); 134struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
161void pcmcia_put_socket(struct pcmcia_socket *skt); 135void pcmcia_put_socket(struct pcmcia_socket *skt);
162 136
137/*
138 * Stuff internal to module "pcmcia".
139 */
140/* ds.c */
141extern struct bus_type pcmcia_bus_type;
142
143/* pcmcia_resource.c */
144extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
145extern int pcmcia_validate_mem(struct pcmcia_socket *s);
146extern 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 */
154extern struct bin_attribute pccard_cis_attr;
155
164int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, 156int 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);
166void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, 158void 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,
172int pcmcia_replace_cis(struct pcmcia_socket *s, 164int pcmcia_replace_cis(struct pcmcia_socket *s,
173 const u8 *data, const size_t len); 165 const u8 *data, const size_t len);
174int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); 166int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count);
167int verify_cis_cache(struct pcmcia_socket *s);
175 168
176/* loop over CIS entries */
177int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, 169int 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,
189int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); 181int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
190 182
191 183
192/* rsrc_mgr.c */
193int pcmcia_validate_mem(struct pcmcia_socket *s);
194struct resource *pcmcia_find_io_region(unsigned long base,
195 int num,
196 unsigned long align,
197 struct pcmcia_socket *s);
198int pcmcia_adjust_io_region(struct resource *res,
199 unsigned long r_start,
200 unsigned long r_end,
201 struct pcmcia_socket *s);
202struct 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 */
212extern struct bus_type pcmcia_bus_type;
213
214/* pcmcia_resource.c */
215extern 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 */
219extern spinlock_t pcmcia_dev_list_lock;
220
221extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); 186extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev);
222extern void pcmcia_put_dev(struct pcmcia_device *p_dev); 187extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
223 188
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");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43 43
44 44
45spinlock_t pcmcia_dev_list_lock;
46
47/*====================================================================*/ 45/*====================================================================*/
48 46
49static void pcmcia_check_driver(struct pcmcia_driver *p_drv) 47static 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
157static int 155static 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)
239static void pcmcia_release_dev(struct device *dev) 237static 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
249static 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
261static int pcmcia_device_probe(struct device *dev) 251static 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
322put_module: 301put_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);
502struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) 491struct 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
637static void pcmcia_delayed_add_device(struct work_struct *work) 638static 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
647static 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
658static 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 */ 650static 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
973static void runtime_resume(struct device *dev) 980static 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);
1295static struct pcmcia_callback pcmcia_bus_callback = { 1337static 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
350static struct of_device_id electra_cf_match[] = { 350static 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
1306static struct of_device_id m8xx_pcmcia_match[] = { 1306static 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
78static int omap_cf_ss_init(struct pcmcia_socket *s) 76static 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);
43static u8 pcmcia_used_irq[NR_IRQS]; 43static u8 pcmcia_used_irq[NR_IRQS];
44#endif 44#endif
45 45
46static 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
54static 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
63int 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
71struct 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 */
208EXPORT_SYMBOL(pcmcia_map_mem_page); 247EXPORT_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)
337static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) 387static 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; 413out:
414 mutex_unlock(&s->ops_mutex);
415
416 return ret;
360} /* pcmcia_release_io */ 417} /* pcmcia_release_io */
361 418
362 419
363static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) 420static 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; 459out:
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
696out:
697 mutex_unlock(&s->ops_mutex);
698
699 return ret;
611} /* pcmcia_request_io */ 700} /* pcmcia_request_io */
612EXPORT_SYMBOL(pcmcia_request_io); 701EXPORT_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;
838out:
839 mutex_unlock(&s->ops_mutex);
840 return ret;
747} /* pcmcia_request_irq */ 841} /* pcmcia_request_irq */
748EXPORT_SYMBOL(pcmcia_request_irq); 842EXPORT_SYMBOL(pcmcia_request_irq);
749 843
@@ -796,6 +890,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
796 return -EINVAL; 890 return -EINVAL;
797 } 891 }
798 892
893 mutex_lock(&s->ops_mutex);
799 win = &s->win[w]; 894 win = &s->win[w];
800 895
801 if (!(s->features & SS_CAP_STATIC_MAP)) { 896 if (!(s->features & SS_CAP_STATIC_MAP)) {
@@ -803,6 +898,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
803 (req->Attributes & WIN_MAP_BELOW_1MB), s); 898 (req->Attributes & WIN_MAP_BELOW_1MB), s);
804 if (!win->res) { 899 if (!win->res) {
805 dev_dbg(&s->dev, "allocating mem region failed\n"); 900 dev_dbg(&s->dev, "allocating mem region failed\n");
901 mutex_unlock(&s->ops_mutex);
806 return -EINVAL; 902 return -EINVAL;
807 } 903 }
808 } 904 }
@@ -821,8 +917,10 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
821 if (req->Attributes & WIN_USE_WAIT) 917 if (req->Attributes & WIN_USE_WAIT)
822 win->flags |= MAP_USE_WAIT; 918 win->flags |= MAP_USE_WAIT;
823 win->card_start = 0; 919 win->card_start = 0;
920
824 if (s->ops->set_mem_map(s, win) != 0) { 921 if (s->ops->set_mem_map(s, win) != 0) {
825 dev_dbg(&s->dev, "failed to set memory mapping\n"); 922 dev_dbg(&s->dev, "failed to set memory mapping\n");
923 mutex_unlock(&s->ops_mutex);
826 return -EIO; 924 return -EIO;
827 } 925 }
828 s->state |= SOCKET_WIN_REQ(w); 926 s->state |= SOCKET_WIN_REQ(w);
@@ -833,6 +931,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
833 else 931 else
834 req->Base = win->res->start; 932 req->Base = win->res->start;
835 933
934 mutex_unlock(&s->ops_mutex);
836 *wh = w + 1; 935 *wh = w + 1;
837 936
838 return 0; 937 return 0;
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index f8401a0ef89b..e6f7d410aed6 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -21,60 +21,12 @@
21#include <pcmcia/cistpl.h> 21#include <pcmcia/cistpl.h>
22#include "cs_internal.h" 22#include "cs_internal.h"
23 23
24
25int 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}
32EXPORT_SYMBOL(pcmcia_validate_mem);
33
34int 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}
41EXPORT_SYMBOL(pcmcia_adjust_io_region);
42
43struct 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}
50EXPORT_SYMBOL(pcmcia_find_io_region);
51
52struct 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}
59EXPORT_SYMBOL(pcmcia_find_mem_region);
60
61void release_resource_db(struct pcmcia_socket *s)
62{
63 if (s->resource_ops->exit)
64 s->resource_ops->exit(s);
65}
66
67
68static int static_init(struct pcmcia_socket *s) 24static 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}
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index c67638fe6914..4663b3fa9f96 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -55,11 +55,10 @@ struct resource_map {
55 55
56struct socket_data { 56struct 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
62static 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 */
275static int readable(struct pcmcia_socket *s, struct resource *res, 273static 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/**
296static int checksum(struct pcmcia_socket *s, struct resource *res) 302 * checksum() - iomem validation function for simple memory cards
303 */
304static 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
327static int 341/**
328cis_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 */
354static 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 382
349static int 383 if ((ret) || (info1 != info2) || (info1 == 0))
350checksum_match(struct pcmcia_socket *s, unsigned long base, unsigned long size) 384 return -EINVAL;
351{
352 struct resource *res1, *res2;
353 int a = -1, b = -1;
354
355 res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe");
356 res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM,
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
376======================================================================*/
377 395
378static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s) 396/**
397 * do_mem_probe() - validate a memory region for PCMCIA use
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 */
410static 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 */
421static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s) 464static 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 */
438static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) 490static 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 */
483static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) 546static 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 */
504static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) 573static 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}
@@ -602,7 +665,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
602 struct socket_data *s_data = s->resource_data; 665 struct socket_data *s_data = s->resource_data;
603 int ret = -ENOMEM; 666 int ret = -ENOMEM;
604 667
605 mutex_lock(&rsrc_mutex);
606 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) {
607 unsigned long start = m->base; 669 unsigned long start = m->base;
608 unsigned long end = m->base + m->num - 1; 670 unsigned long end = m->base + m->num - 1;
@@ -613,7 +675,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
613 ret = adjust_resource(res, r_start, r_end - r_start + 1); 675 ret = adjust_resource(res, r_start, r_end - r_start + 1);
614 break; 676 break;
615 } 677 }
616 mutex_unlock(&rsrc_mutex);
617 678
618 return ret; 679 return ret;
619} 680}
@@ -647,7 +708,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
647 data.offset = base & data.mask; 708 data.offset = base & data.mask;
648 data.map = &s_data->io_db; 709 data.map = &s_data->io_db;
649 710
650 mutex_lock(&rsrc_mutex);
651#ifdef CONFIG_PCI 711#ifdef CONFIG_PCI
652 if (s->cb_dev) { 712 if (s->cb_dev) {
653 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,
@@ -656,7 +716,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
656#endif 716#endif
657 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 717 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
658 1, pcmcia_align, &data); 718 1, pcmcia_align, &data);
659 mutex_unlock(&rsrc_mutex);
660 719
661 if (ret != 0) { 720 if (ret != 0) {
662 kfree(res); 721 kfree(res);
@@ -672,15 +731,15 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num,
672 struct socket_data *s_data = s->resource_data; 731 struct socket_data *s_data = s->resource_data;
673 struct pcmcia_align_data data; 732 struct pcmcia_align_data data;
674 unsigned long min, max; 733 unsigned long min, max;
675 int ret, i; 734 int ret, i, j;
676 735
677 low = low || !(s->features & SS_CAP_PAGE_REGS); 736 low = low || !(s->features & SS_CAP_PAGE_REGS);
678 737
679 data.mask = align - 1; 738 data.mask = align - 1;
680 data.offset = base & data.mask; 739 data.offset = base & data.mask;
681 data.map = &s_data->mem_db;
682 740
683 for (i = 0; i < 2; i++) { 741 for (i = 0; i < 2; i++) {
742 data.map = &s_data->mem_db_valid;
684 if (low) { 743 if (low) {
685 max = 0x100000UL; 744 max = 0x100000UL;
686 min = base < max ? base : 0; 745 min = base < max ? base : 0;
@@ -689,17 +748,23 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num,
689 min = 0x100000UL + base; 748 min = 0x100000UL + base;
690 } 749 }
691 750
692 mutex_lock(&rsrc_mutex); 751 for (j = 0; j < 2; j++) {
693#ifdef CONFIG_PCI 752#ifdef CONFIG_PCI
694 if (s->cb_dev) { 753 if (s->cb_dev) {
695 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 754 ret = pci_bus_alloc_resource(s->cb_dev->bus,
696 1, min, 0, 755 res, num, 1, min, 0,
697 pcmcia_align, &data); 756 pcmcia_align, &data);
698 } else 757 } else
699#endif 758#endif
700 ret = allocate_resource(&iomem_resource, res, num, min, 759 {
701 max, 1, pcmcia_align, &data); 760 ret = allocate_resource(&iomem_resource,
702 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 }
703 if (ret == 0 || low) 768 if (ret == 0 || low)
704 break; 769 break;
705 low = 1; 770 low = 1;
@@ -722,25 +787,18 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned
722 if (end < start) 787 if (end < start)
723 return -EINVAL; 788 return -EINVAL;
724 789
725 mutex_lock(&rsrc_mutex);
726 switch (action) { 790 switch (action) {
727 case ADD_MANAGED_RESOURCE: 791 case ADD_MANAGED_RESOURCE:
728 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);
729 break; 795 break;
730 case REMOVE_MANAGED_RESOURCE: 796 case REMOVE_MANAGED_RESOURCE:
731 ret = sub_interval(&data->mem_db, start, size); 797 ret = sub_interval(&data->mem_db, start, size);
732 if (!ret) {
733 struct pcmcia_socket *socket;
734 down_read(&pcmcia_socket_list_rwsem);
735 list_for_each_entry(socket, &pcmcia_socket_list, socket_list)
736 release_cis_mem(socket);
737 up_read(&pcmcia_socket_list_rwsem);
738 }
739 break; 798 break;
740 default: 799 default:
741 ret = -EINVAL; 800 ret = -EINVAL;
742 } 801 }
743 mutex_unlock(&rsrc_mutex);
744 802
745 return ret; 803 return ret;
746} 804}
@@ -758,7 +816,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
758 if (end > IO_SPACE_LIMIT) 816 if (end > IO_SPACE_LIMIT)
759 return -EINVAL; 817 return -EINVAL;
760 818
761 mutex_lock(&rsrc_mutex);
762 switch (action) { 819 switch (action) {
763 case ADD_MANAGED_RESOURCE: 820 case ADD_MANAGED_RESOURCE:
764 if (add_interval(&data->io_db, start, size) != 0) { 821 if (add_interval(&data->io_db, start, size) != 0) {
@@ -777,7 +834,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
777 ret = -EINVAL; 834 ret = -EINVAL;
778 break; 835 break;
779 } 836 }
780 mutex_unlock(&rsrc_mutex);
781 837
782 return ret; 838 return ret;
783} 839}
@@ -860,6 +916,7 @@ static int nonstatic_init(struct pcmcia_socket *s)
860 return -ENOMEM; 916 return -ENOMEM;
861 917
862 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;
863 data->io_db.next = &data->io_db; 920 data->io_db.next = &data->io_db;
864 921
865 s->resource_data = (void *) data; 922 s->resource_data = (void *) data;
@@ -874,7 +931,10 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
874 struct socket_data *data = s->resource_data; 931 struct socket_data *data = s->resource_data;
875 struct resource_map *p, *q; 932 struct resource_map *p, *q;
876 933
877 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 }
878 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) {
879 q = p->next; 939 q = p->next;
880 kfree(p); 940 kfree(p);
@@ -883,7 +943,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
883 q = p->next; 943 q = p->next;
884 kfree(p); 944 kfree(p);
885 } 945 }
886 mutex_unlock(&rsrc_mutex);
887} 946}
888 947
889 948
@@ -910,7 +969,7 @@ static ssize_t show_io_db(struct device *dev,
910 struct resource_map *p; 969 struct resource_map *p;
911 ssize_t ret = 0; 970 ssize_t ret = 0;
912 971
913 mutex_lock(&rsrc_mutex); 972 mutex_lock(&s->ops_mutex);
914 data = s->resource_data; 973 data = s->resource_data;
915 974
916 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) {
@@ -922,7 +981,7 @@ static ssize_t show_io_db(struct device *dev,
922 ((unsigned long) p->base + p->num - 1)); 981 ((unsigned long) p->base + p->num - 1));
923 } 982 }
924 983
925 mutex_unlock(&rsrc_mutex); 984 mutex_unlock(&s->ops_mutex);
926 return ret; 985 return ret;
927} 986}
928 987
@@ -950,9 +1009,11 @@ static ssize_t store_io_db(struct device *dev,
950 if (end_addr < start_addr) 1009 if (end_addr < start_addr)
951 return -EINVAL; 1010 return -EINVAL;
952 1011
1012 mutex_lock(&s->ops_mutex);
953 ret = adjust_io(s, add, start_addr, end_addr); 1013 ret = adjust_io(s, add, start_addr, end_addr);
954 if (!ret) 1014 if (!ret)
955 s->resource_setup_new = 1; 1015 s->resource_setup_new = 1;
1016 mutex_unlock(&s->ops_mutex);
956 1017
957 return ret ? ret : count; 1018 return ret ? ret : count;
958} 1019}
@@ -966,9 +1027,19 @@ static ssize_t show_mem_db(struct device *dev,
966 struct resource_map *p; 1027 struct resource_map *p;
967 ssize_t ret = 0; 1028 ssize_t ret = 0;
968 1029
969 mutex_lock(&rsrc_mutex); 1030 mutex_lock(&s->ops_mutex);
970 data = s->resource_data; 1031 data = s->resource_data;
971 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
972 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) {
973 if (ret > (PAGE_SIZE - 10)) 1044 if (ret > (PAGE_SIZE - 10))
974 continue; 1045 continue;
@@ -978,7 +1049,7 @@ static ssize_t show_mem_db(struct device *dev,
978 ((unsigned long) p->base + p->num - 1)); 1049 ((unsigned long) p->base + p->num - 1));
979 } 1050 }
980 1051
981 mutex_unlock(&rsrc_mutex); 1052 mutex_unlock(&s->ops_mutex);
982 return ret; 1053 return ret;
983} 1054}
984 1055
@@ -1006,9 +1077,11 @@ static ssize_t store_mem_db(struct device *dev,
1006 if (end_addr < start_addr) 1077 if (end_addr < start_addr)
1007 return -EINVAL; 1078 return -EINVAL;
1008 1079
1080 mutex_lock(&s->ops_mutex);
1009 ret = adjust_memory(s, add, start_addr, end_addr); 1081 ret = adjust_memory(s, add, start_addr, end_addr);
1010 if (!ret) 1082 if (!ret)
1011 s->resource_setup_new = 1; 1083 s->resource_setup_new = 1;
1084 mutex_unlock(&s->ops_mutex);
1012 1085
1013 return ret ? ret : count; 1086 return ret ? ret : count;
1014} 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);
88static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, 88static 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}
101static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); 100static 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}
129static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state); 132static 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}
145static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); 147static 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}
214static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
215 203
216 204 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
217static 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
284static 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
314static 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 208static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
347 209
348static struct attribute *pccard_socket_attributes[] = { 210static 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
365static 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
372int pccard_sysfs_add_socket(struct device *dev) 227int 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
385void pccard_sysfs_remove_socket(struct device *dev) 232void 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/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 1f2039d5e966..b85375f87622 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -37,6 +37,11 @@ static int pwr_irqs_off;
37module_param(pwr_irqs_off, bool, 0644); 37module_param(pwr_irqs_off, bool, 0644);
38MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!"); 38MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
39 39
40static char o2_speedup[] = "default";
41module_param_string(o2_speedup, o2_speedup, sizeof(o2_speedup), 0444);
42MODULE_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.. */
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 95421fa3b304..e91db4b38012 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -696,11 +696,11 @@ static int serial_config(struct pcmcia_device * link)
696 info->multi = info->quirk->multi; 696 info->multi = info->quirk->multi;
697 697
698 if (info->multi > 1) 698 if (info->multi > 1)
699 multi_config(link); 699 i = multi_config(link);
700 else 700 else
701 simple_config(link); 701 i = simple_config(link);
702 702
703 if (info->ndev == 0) 703 if (i || info->ndev == 0)
704 goto failed; 704 goto failed;
705 705
706 /* 706 /*
@@ -715,6 +715,7 @@ static int serial_config(struct pcmcia_device * link)
715 return 0; 715 return 0;
716 716
717failed: 717failed:
718 dev_warn(&link->dev, "serial_cs: failed to initialize\n");
718 serial_remove(link); 719 serial_remove(link);
719 return -ENODEV; 720 return -ENODEV;
720} 721}
diff --git a/include/pcmcia/ds.h b/include/pcmcia/ds.h
index ee148573c114..d57847f2f6c1 100644
--- a/include/pcmcia/ds.h
+++ b/include/pcmcia/ds.h
@@ -40,7 +40,7 @@ struct net_device;
40 * Documentation/pcmcia/driver.txt for details. 40 * Documentation/pcmcia/driver.txt for details.
41*/ 41*/
42struct pcmcia_dynids { 42struct pcmcia_dynids {
43 spinlock_t lock; 43 struct mutex lock;
44 struct list_head list; 44 struct list_head list;
45}; 45};
46 46
diff --git a/include/pcmcia/ss.h b/include/pcmcia/ss.h
index cbfba885eb85..32896a773910 100644
--- a/include/pcmcia/ss.h
+++ b/include/pcmcia/ss.h
@@ -134,9 +134,9 @@ struct pccard_operations {
134 134
135struct pcmcia_socket { 135struct pcmcia_socket {
136 struct module *owner; 136 struct module *owner;
137 spinlock_t lock;
138 socket_state_t socket; 137 socket_state_t socket;
139 u_int state; 138 u_int state;
139 u_int suspended_state; /* state before suspend */
140 u_short functions; 140 u_short functions;
141 u_short lock_count; 141 u_short lock_count;
142 pccard_mem_map cis_mem; 142 pccard_mem_map cis_mem;
@@ -200,9 +200,14 @@ struct pcmcia_socket {
200 struct task_struct *thread; 200 struct task_struct *thread;
201 struct completion thread_done; 201 struct completion thread_done;
202 unsigned int thread_events; 202 unsigned int thread_events;
203 /* protects socket h/w state */ 203 unsigned int sysfs_events;
204
205 /* For the non-trivial interaction between these locks,
206 * see Documentation/pcmcia/locking.txt */
204 struct mutex skt_mutex; 207 struct mutex skt_mutex;
205 /* protects thread_events */ 208 struct mutex ops_mutex;
209
210 /* protects thread_events and sysfs_events */
206 spinlock_t thread_lock; 211 spinlock_t thread_lock;
207 212
208 /* pcmcia (16-bit) */ 213 /* pcmcia (16-bit) */
@@ -225,30 +230,19 @@ struct pcmcia_socket {
225 u8 busy:1; 230 u8 busy:1;
226 /* pcmcia module is being unloaded */ 231 /* pcmcia module is being unloaded */
227 u8 dead:1; 232 u8 dead:1;
228 /* a multifunction-device add event is pending */ 233 /* the PCMCIA card consists of two pseudo devices */
229 u8 device_add_pending:1; 234 u8 has_pfc:1;
230 /* the pending event adds a mfc (1) or pfc (0) */
231 u8 mfc_pfc:1;
232 235
233 u8 reserved:3; 236 u8 reserved:4;
234 } pcmcia_state; 237 } pcmcia_state;
235 238
236 239
237 /* for adding further pseudo-multifunction devices */
238 struct work_struct device_add;
239
240#ifdef CONFIG_PCMCIA_IOCTL 240#ifdef CONFIG_PCMCIA_IOCTL
241 struct user_info_t *user; 241 struct user_info_t *user;
242 wait_queue_head_t queue; 242 wait_queue_head_t queue;
243#endif /* CONFIG_PCMCIA_IOCTL */ 243#endif /* CONFIG_PCMCIA_IOCTL */
244#endif /* CONFIG_PCMCIA */ 244#endif /* CONFIG_PCMCIA */
245 245
246 /* cardbus (32-bit) */
247#ifdef CONFIG_CARDBUS
248 struct resource *cb_cis_res;
249 void __iomem *cb_cis_virt;
250#endif /* CONFIG_CARDBUS */
251
252 /* socket device */ 246 /* socket device */
253 struct device dev; 247 struct device dev;
254 /* data internal to the socket driver */ 248 /* data internal to the socket driver */
@@ -263,13 +257,25 @@ struct pcmcia_socket {
263 * - pccard_static_ops iomem and ioport areas are assigned statically 257 * - pccard_static_ops iomem and ioport areas are assigned statically
264 * - pccard_iodyn_ops iomem areas is assigned statically, ioport 258 * - pccard_iodyn_ops iomem areas is assigned statically, ioport
265 * areas dynamically 259 * areas dynamically
260 * If this option is selected, use
261 * "select PCCARD_IODYN" in Kconfig.
266 * - pccard_nonstatic_ops iomem and ioport areas are assigned dynamically. 262 * - pccard_nonstatic_ops iomem and ioport areas are assigned dynamically.
267 * If this option is selected, use 263 * If this option is selected, use
268 * "select PCCARD_NONSTATIC" in Kconfig. 264 * "select PCCARD_NONSTATIC" in Kconfig.
265 *
269 */ 266 */
270extern struct pccard_resource_ops pccard_static_ops; 267extern struct pccard_resource_ops pccard_static_ops;
268#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
271extern struct pccard_resource_ops pccard_iodyn_ops; 269extern struct pccard_resource_ops pccard_iodyn_ops;
272extern struct pccard_resource_ops pccard_nonstatic_ops; 270extern struct pccard_resource_ops pccard_nonstatic_ops;
271#else
272/* If PCMCIA is not used, but only CARDBUS, these functions are not used
273 * at all. Therefore, do not use the large (240K!) rsrc_nonstatic module
274 */
275#define pccard_iodyn_ops pccard_static_ops
276#define pccard_nonstatic_ops pccard_static_ops
277#endif
278
273 279
274/* socket drivers are expected to use these callbacks in their .drv struct */ 280/* socket drivers are expected to use these callbacks in their .drv struct */
275extern int pcmcia_socket_dev_suspend(struct device *dev); 281extern int pcmcia_socket_dev_suspend(struct device *dev);