diff options
Diffstat (limited to 'drivers/pcmcia/pcmcia_resource.c')
-rw-r--r-- | drivers/pcmcia/pcmcia_resource.c | 381 |
1 files changed, 214 insertions, 167 deletions
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index 4884a18cf9e6..afea2b2558b5 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <pcmcia/ds.h> | 29 | #include <pcmcia/ds.h> |
30 | 30 | ||
31 | #include "cs_internal.h" | 31 | #include "cs_internal.h" |
32 | #include "ds_internal.h" | ||
33 | 32 | ||
34 | 33 | ||
35 | /* Access speed for IO windows */ | 34 | /* Access speed for IO windows */ |
@@ -44,16 +43,17 @@ static u8 pcmcia_used_irq[NR_IRQS]; | |||
44 | #endif | 43 | #endif |
45 | 44 | ||
46 | 45 | ||
47 | #ifdef DEBUG | 46 | #ifdef CONFIG_PCMCIA_DEBUG |
48 | extern int ds_pc_debug; | 47 | extern int ds_pc_debug; |
49 | 48 | ||
50 | #define ds_dbg(skt, lvl, fmt, arg...) do { \ | 49 | #define ds_dbg(skt, lvl, fmt, arg...) do { \ |
51 | if (ds_pc_debug >= lvl) \ | 50 | if (ds_pc_debug >= lvl) \ |
52 | printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \ | 51 | dev_printk(KERN_DEBUG, &skt->dev, \ |
53 | cs_socket_name(skt) , ## arg); \ | 52 | "pcmcia_resource: " fmt, \ |
53 | ## arg); \ | ||
54 | } while (0) | 54 | } while (0) |
55 | #else | 55 | #else |
56 | #define ds_dbg(lvl, fmt, arg...) do { } while (0) | 56 | #define ds_dbg(skt, lvl, fmt, arg...) do { } while (0) |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
@@ -168,13 +168,13 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, | |||
168 | u_char val; | 168 | u_char val; |
169 | 169 | ||
170 | if (!p_dev || !p_dev->function_config) | 170 | if (!p_dev || !p_dev->function_config) |
171 | return CS_NO_CARD; | 171 | return -EINVAL; |
172 | 172 | ||
173 | s = p_dev->socket; | 173 | s = p_dev->socket; |
174 | c = p_dev->function_config; | 174 | c = p_dev->function_config; |
175 | 175 | ||
176 | if (!(c->state & CONFIG_LOCKED)) | 176 | if (!(c->state & CONFIG_LOCKED)) |
177 | return CS_CONFIGURATION_LOCKED; | 177 | return -EACCES; |
178 | 178 | ||
179 | addr = (c->ConfigBase + reg->Offset) >> 1; | 179 | addr = (c->ConfigBase + reg->Offset) >> 1; |
180 | 180 | ||
@@ -188,93 +188,14 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, | |||
188 | pcmcia_write_cis_mem(s, 1, addr, 1, &val); | 188 | pcmcia_write_cis_mem(s, 1, addr, 1, &val); |
189 | break; | 189 | break; |
190 | default: | 190 | default: |
191 | return CS_BAD_ARGS; | 191 | return -EINVAL; |
192 | break; | 192 | break; |
193 | } | 193 | } |
194 | return CS_SUCCESS; | 194 | return 0; |
195 | } /* pcmcia_access_configuration_register */ | 195 | } /* pcmcia_access_configuration_register */ |
196 | EXPORT_SYMBOL(pcmcia_access_configuration_register); | 196 | EXPORT_SYMBOL(pcmcia_access_configuration_register); |
197 | 197 | ||
198 | 198 | ||
199 | int pccard_get_configuration_info(struct pcmcia_socket *s, | ||
200 | struct pcmcia_device *p_dev, | ||
201 | config_info_t *config) | ||
202 | { | ||
203 | config_t *c; | ||
204 | |||
205 | if (!(s->state & SOCKET_PRESENT)) | ||
206 | return CS_NO_CARD; | ||
207 | |||
208 | |||
209 | #ifdef CONFIG_CARDBUS | ||
210 | if (s->state & SOCKET_CARDBUS) { | ||
211 | memset(config, 0, sizeof(config_info_t)); | ||
212 | config->Vcc = s->socket.Vcc; | ||
213 | config->Vpp1 = config->Vpp2 = s->socket.Vpp; | ||
214 | config->Option = s->cb_dev->subordinate->number; | ||
215 | if (s->state & SOCKET_CARDBUS_CONFIG) { | ||
216 | config->Attributes = CONF_VALID_CLIENT; | ||
217 | config->IntType = INT_CARDBUS; | ||
218 | config->AssignedIRQ = s->irq.AssignedIRQ; | ||
219 | if (config->AssignedIRQ) | ||
220 | config->Attributes |= CONF_ENABLE_IRQ; | ||
221 | if (s->io[0].res) { | ||
222 | config->BasePort1 = s->io[0].res->start; | ||
223 | config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1; | ||
224 | } | ||
225 | } | ||
226 | return CS_SUCCESS; | ||
227 | } | ||
228 | #endif | ||
229 | |||
230 | if (p_dev) { | ||
231 | c = p_dev->function_config; | ||
232 | config->Function = p_dev->func; | ||
233 | } else { | ||
234 | c = NULL; | ||
235 | config->Function = 0; | ||
236 | } | ||
237 | |||
238 | if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { | ||
239 | config->Attributes = 0; | ||
240 | config->Vcc = s->socket.Vcc; | ||
241 | config->Vpp1 = config->Vpp2 = s->socket.Vpp; | ||
242 | return CS_SUCCESS; | ||
243 | } | ||
244 | |||
245 | config->Attributes = c->Attributes | CONF_VALID_CLIENT; | ||
246 | config->Vcc = s->socket.Vcc; | ||
247 | config->Vpp1 = config->Vpp2 = s->socket.Vpp; | ||
248 | config->IntType = c->IntType; | ||
249 | config->ConfigBase = c->ConfigBase; | ||
250 | config->Status = c->Status; | ||
251 | config->Pin = c->Pin; | ||
252 | config->Copy = c->Copy; | ||
253 | config->Option = c->Option; | ||
254 | config->ExtStatus = c->ExtStatus; | ||
255 | config->Present = config->CardValues = c->CardValues; | ||
256 | config->IRQAttributes = c->irq.Attributes; | ||
257 | config->AssignedIRQ = s->irq.AssignedIRQ; | ||
258 | config->BasePort1 = c->io.BasePort1; | ||
259 | config->NumPorts1 = c->io.NumPorts1; | ||
260 | config->Attributes1 = c->io.Attributes1; | ||
261 | config->BasePort2 = c->io.BasePort2; | ||
262 | config->NumPorts2 = c->io.NumPorts2; | ||
263 | config->Attributes2 = c->io.Attributes2; | ||
264 | config->IOAddrLines = c->io.IOAddrLines; | ||
265 | |||
266 | return CS_SUCCESS; | ||
267 | } /* pccard_get_configuration_info */ | ||
268 | |||
269 | int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, | ||
270 | config_info_t *config) | ||
271 | { | ||
272 | return pccard_get_configuration_info(p_dev->socket, p_dev, | ||
273 | config); | ||
274 | } | ||
275 | EXPORT_SYMBOL(pcmcia_get_configuration_info); | ||
276 | |||
277 | |||
278 | /** pcmcia_get_window | 199 | /** pcmcia_get_window |
279 | */ | 200 | */ |
280 | int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, | 201 | int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, |
@@ -284,12 +205,12 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, | |||
284 | int w; | 205 | int w; |
285 | 206 | ||
286 | if (!s || !(s->state & SOCKET_PRESENT)) | 207 | if (!s || !(s->state & SOCKET_PRESENT)) |
287 | return CS_NO_CARD; | 208 | return -ENODEV; |
288 | for (w = idx; w < MAX_WIN; w++) | 209 | for (w = idx; w < MAX_WIN; w++) |
289 | if (s->state & SOCKET_WIN_REQ(w)) | 210 | if (s->state & SOCKET_WIN_REQ(w)) |
290 | break; | 211 | break; |
291 | if (w == MAX_WIN) | 212 | if (w == MAX_WIN) |
292 | return CS_NO_MORE_ITEMS; | 213 | return -EINVAL; |
293 | win = &s->win[w]; | 214 | win = &s->win[w]; |
294 | req->Base = win->ctl.res->start; | 215 | req->Base = win->ctl.res->start; |
295 | req->Size = win->ctl.res->end - win->ctl.res->start + 1; | 216 | req->Size = win->ctl.res->end - win->ctl.res->start + 1; |
@@ -304,7 +225,7 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, | |||
304 | if (win->ctl.flags & MAP_USE_WAIT) | 225 | if (win->ctl.flags & MAP_USE_WAIT) |
305 | req->Attributes |= WIN_USE_WAIT; | 226 | req->Attributes |= WIN_USE_WAIT; |
306 | *handle = win; | 227 | *handle = win; |
307 | return CS_SUCCESS; | 228 | return 0; |
308 | } /* pcmcia_get_window */ | 229 | } /* pcmcia_get_window */ |
309 | EXPORT_SYMBOL(pcmcia_get_window); | 230 | EXPORT_SYMBOL(pcmcia_get_window); |
310 | 231 | ||
@@ -316,10 +237,10 @@ EXPORT_SYMBOL(pcmcia_get_window); | |||
316 | int pcmcia_get_mem_page(window_handle_t win, memreq_t *req) | 237 | int pcmcia_get_mem_page(window_handle_t win, memreq_t *req) |
317 | { | 238 | { |
318 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) | 239 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) |
319 | return CS_BAD_HANDLE; | 240 | return -EINVAL; |
320 | req->Page = 0; | 241 | req->Page = 0; |
321 | req->CardOffset = win->ctl.card_start; | 242 | req->CardOffset = win->ctl.card_start; |
322 | return CS_SUCCESS; | 243 | return 0; |
323 | } /* pcmcia_get_mem_page */ | 244 | } /* pcmcia_get_mem_page */ |
324 | EXPORT_SYMBOL(pcmcia_get_mem_page); | 245 | EXPORT_SYMBOL(pcmcia_get_mem_page); |
325 | 246 | ||
@@ -328,14 +249,18 @@ int pcmcia_map_mem_page(window_handle_t win, memreq_t *req) | |||
328 | { | 249 | { |
329 | struct pcmcia_socket *s; | 250 | struct pcmcia_socket *s; |
330 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) | 251 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) |
331 | return CS_BAD_HANDLE; | 252 | return -EINVAL; |
332 | if (req->Page != 0) | ||
333 | return CS_BAD_PAGE; | ||
334 | s = win->sock; | 253 | s = win->sock; |
254 | if (req->Page != 0) { | ||
255 | ds_dbg(s, 0, "failure: requested page is zero\n"); | ||
256 | return -EINVAL; | ||
257 | } | ||
335 | win->ctl.card_start = req->CardOffset; | 258 | win->ctl.card_start = req->CardOffset; |
336 | if (s->ops->set_mem_map(s, &win->ctl) != 0) | 259 | if (s->ops->set_mem_map(s, &win->ctl) != 0) { |
337 | return CS_BAD_OFFSET; | 260 | ds_dbg(s, 0, "failed to set_mem_map\n"); |
338 | return CS_SUCCESS; | 261 | return -EIO; |
262 | } | ||
263 | return 0; | ||
339 | } /* pcmcia_map_mem_page */ | 264 | } /* pcmcia_map_mem_page */ |
340 | EXPORT_SYMBOL(pcmcia_map_mem_page); | 265 | EXPORT_SYMBOL(pcmcia_map_mem_page); |
341 | 266 | ||
@@ -354,9 +279,9 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
354 | c = p_dev->function_config; | 279 | c = p_dev->function_config; |
355 | 280 | ||
356 | if (!(s->state & SOCKET_PRESENT)) | 281 | if (!(s->state & SOCKET_PRESENT)) |
357 | return CS_NO_CARD; | 282 | return -ENODEV; |
358 | if (!(c->state & CONFIG_LOCKED)) | 283 | if (!(c->state & CONFIG_LOCKED)) |
359 | return CS_CONFIGURATION_LOCKED; | 284 | return -EACCES; |
360 | 285 | ||
361 | if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { | 286 | if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { |
362 | if (mod->Attributes & CONF_ENABLE_IRQ) { | 287 | if (mod->Attributes & CONF_ENABLE_IRQ) { |
@@ -369,20 +294,28 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
369 | s->ops->set_socket(s, &s->socket); | 294 | s->ops->set_socket(s, &s->socket); |
370 | } | 295 | } |
371 | 296 | ||
372 | if (mod->Attributes & CONF_VCC_CHANGE_VALID) | 297 | if (mod->Attributes & CONF_VCC_CHANGE_VALID) { |
373 | return CS_BAD_VCC; | 298 | ds_dbg(s, 0, "changing Vcc is not allowed at this time\n"); |
299 | return -EINVAL; | ||
300 | } | ||
374 | 301 | ||
375 | /* We only allow changing Vpp1 and Vpp2 to the same value */ | 302 | /* We only allow changing Vpp1 and Vpp2 to the same value */ |
376 | if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && | 303 | if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && |
377 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { | 304 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
378 | if (mod->Vpp1 != mod->Vpp2) | 305 | if (mod->Vpp1 != mod->Vpp2) |
379 | return CS_BAD_VPP; | 306 | ds_dbg(s, 0, "Vpp1 and Vpp2 must be the same\n"); |
307 | return -EINVAL; | ||
380 | s->socket.Vpp = mod->Vpp1; | 308 | s->socket.Vpp = mod->Vpp1; |
381 | if (s->ops->set_socket(s, &s->socket)) | 309 | if (s->ops->set_socket(s, &s->socket)) { |
382 | return CS_BAD_VPP; | 310 | dev_printk(KERN_WARNING, &s->dev, |
311 | "Unable to set VPP\n"); | ||
312 | return -EIO; | ||
313 | } | ||
383 | } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || | 314 | } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || |
384 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) | 315 | (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { |
385 | return CS_BAD_VPP; | 316 | ds_dbg(s, 0, "changing Vcc is not allowed at this time\n"); |
317 | return -EINVAL; | ||
318 | } | ||
386 | 319 | ||
387 | if (mod->Attributes & CONF_IO_CHANGE_WIDTH) { | 320 | if (mod->Attributes & CONF_IO_CHANGE_WIDTH) { |
388 | pccard_io_map io_off = { 0, 0, 0, 0, 1 }; | 321 | pccard_io_map io_off = { 0, 0, 0, 0, 1 }; |
@@ -406,7 +339,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev, | |||
406 | } | 339 | } |
407 | } | 340 | } |
408 | 341 | ||
409 | return CS_SUCCESS; | 342 | return 0; |
410 | } /* modify_configuration */ | 343 | } /* modify_configuration */ |
411 | EXPORT_SYMBOL(pcmcia_modify_configuration); | 344 | EXPORT_SYMBOL(pcmcia_modify_configuration); |
412 | 345 | ||
@@ -441,7 +374,7 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) | |||
441 | } | 374 | } |
442 | } | 375 | } |
443 | 376 | ||
444 | return CS_SUCCESS; | 377 | return 0; |
445 | } /* pcmcia_release_configuration */ | 378 | } /* pcmcia_release_configuration */ |
446 | 379 | ||
447 | 380 | ||
@@ -459,7 +392,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
459 | config_t *c = p_dev->function_config; | 392 | config_t *c = p_dev->function_config; |
460 | 393 | ||
461 | if (!p_dev->_io ) | 394 | if (!p_dev->_io ) |
462 | return CS_BAD_HANDLE; | 395 | return -EINVAL; |
463 | 396 | ||
464 | p_dev->_io = 0; | 397 | p_dev->_io = 0; |
465 | 398 | ||
@@ -467,7 +400,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
467 | (c->io.NumPorts1 != req->NumPorts1) || | 400 | (c->io.NumPorts1 != req->NumPorts1) || |
468 | (c->io.BasePort2 != req->BasePort2) || | 401 | (c->io.BasePort2 != req->BasePort2) || |
469 | (c->io.NumPorts2 != req->NumPorts2)) | 402 | (c->io.NumPorts2 != req->NumPorts2)) |
470 | return CS_BAD_ARGS; | 403 | return -EINVAL; |
471 | 404 | ||
472 | c->state &= ~CONFIG_IO_REQ; | 405 | c->state &= ~CONFIG_IO_REQ; |
473 | 406 | ||
@@ -475,7 +408,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
475 | if (req->NumPorts2) | 408 | if (req->NumPorts2) |
476 | release_io_space(s, req->BasePort2, req->NumPorts2); | 409 | release_io_space(s, req->BasePort2, req->NumPorts2); |
477 | 410 | ||
478 | return CS_SUCCESS; | 411 | return 0; |
479 | } /* pcmcia_release_io */ | 412 | } /* pcmcia_release_io */ |
480 | 413 | ||
481 | 414 | ||
@@ -485,15 +418,19 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
485 | config_t *c= p_dev->function_config; | 418 | config_t *c= p_dev->function_config; |
486 | 419 | ||
487 | if (!p_dev->_irq) | 420 | if (!p_dev->_irq) |
488 | return CS_BAD_HANDLE; | 421 | return -EINVAL; |
489 | p_dev->_irq = 0; | 422 | p_dev->_irq = 0; |
490 | 423 | ||
491 | if (c->state & CONFIG_LOCKED) | 424 | if (c->state & CONFIG_LOCKED) |
492 | return CS_CONFIGURATION_LOCKED; | 425 | return -EACCES; |
493 | if (c->irq.Attributes != req->Attributes) | 426 | if (c->irq.Attributes != req->Attributes) { |
494 | return CS_BAD_ATTRIBUTE; | 427 | ds_dbg(s, 0, "IRQ attributes must match assigned ones\n"); |
495 | if (s->irq.AssignedIRQ != req->AssignedIRQ) | 428 | return -EINVAL; |
496 | return CS_BAD_IRQ; | 429 | } |
430 | if (s->irq.AssignedIRQ != req->AssignedIRQ) { | ||
431 | ds_dbg(s, 0, "IRQ must match assigned one\n"); | ||
432 | return -EINVAL; | ||
433 | } | ||
497 | if (--s->irq.Config == 0) { | 434 | if (--s->irq.Config == 0) { |
498 | c->state &= ~CONFIG_IRQ_REQ; | 435 | c->state &= ~CONFIG_IRQ_REQ; |
499 | s->irq.AssignedIRQ = 0; | 436 | s->irq.AssignedIRQ = 0; |
@@ -507,7 +444,7 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
507 | pcmcia_used_irq[req->AssignedIRQ]--; | 444 | pcmcia_used_irq[req->AssignedIRQ]--; |
508 | #endif | 445 | #endif |
509 | 446 | ||
510 | return CS_SUCCESS; | 447 | return 0; |
511 | } /* pcmcia_release_irq */ | 448 | } /* pcmcia_release_irq */ |
512 | 449 | ||
513 | 450 | ||
@@ -516,10 +453,10 @@ int pcmcia_release_window(window_handle_t win) | |||
516 | struct pcmcia_socket *s; | 453 | struct pcmcia_socket *s; |
517 | 454 | ||
518 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) | 455 | if ((win == NULL) || (win->magic != WINDOW_MAGIC)) |
519 | return CS_BAD_HANDLE; | 456 | return -EINVAL; |
520 | s = win->sock; | 457 | s = win->sock; |
521 | if (!(win->handle->_win & CLIENT_WIN_REQ(win->index))) | 458 | if (!(win->handle->_win & CLIENT_WIN_REQ(win->index))) |
522 | return CS_BAD_HANDLE; | 459 | return -EINVAL; |
523 | 460 | ||
524 | /* Shut down memory window */ | 461 | /* Shut down memory window */ |
525 | win->ctl.flags &= ~MAP_ACTIVE; | 462 | win->ctl.flags &= ~MAP_ACTIVE; |
@@ -536,7 +473,7 @@ int pcmcia_release_window(window_handle_t win) | |||
536 | 473 | ||
537 | win->magic = 0; | 474 | win->magic = 0; |
538 | 475 | ||
539 | return CS_SUCCESS; | 476 | return 0; |
540 | } /* pcmcia_release_window */ | 477 | } /* pcmcia_release_window */ |
541 | EXPORT_SYMBOL(pcmcia_release_window); | 478 | EXPORT_SYMBOL(pcmcia_release_window); |
542 | 479 | ||
@@ -551,18 +488,23 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
551 | pccard_io_map iomap; | 488 | pccard_io_map iomap; |
552 | 489 | ||
553 | if (!(s->state & SOCKET_PRESENT)) | 490 | if (!(s->state & SOCKET_PRESENT)) |
554 | return CS_NO_CARD; | 491 | return -ENODEV;; |
555 | 492 | ||
556 | if (req->IntType & INT_CARDBUS) | 493 | if (req->IntType & INT_CARDBUS) { |
557 | return CS_UNSUPPORTED_MODE; | 494 | ds_dbg(p_dev->socket, 0, "IntType may not be INT_CARDBUS\n"); |
495 | return -EINVAL; | ||
496 | } | ||
558 | c = p_dev->function_config; | 497 | c = p_dev->function_config; |
559 | if (c->state & CONFIG_LOCKED) | 498 | if (c->state & CONFIG_LOCKED) |
560 | return CS_CONFIGURATION_LOCKED; | 499 | return -EACCES; |
561 | 500 | ||
562 | /* Do power control. We don't allow changes in Vcc. */ | 501 | /* Do power control. We don't allow changes in Vcc. */ |
563 | s->socket.Vpp = req->Vpp; | 502 | s->socket.Vpp = req->Vpp; |
564 | if (s->ops->set_socket(s, &s->socket)) | 503 | if (s->ops->set_socket(s, &s->socket)) { |
565 | return CS_BAD_VPP; | 504 | dev_printk(KERN_WARNING, &s->dev, |
505 | "Unable to set socket state\n"); | ||
506 | return -EINVAL; | ||
507 | } | ||
566 | 508 | ||
567 | /* Pick memory or I/O card, DMA mode, interrupt */ | 509 | /* Pick memory or I/O card, DMA mode, interrupt */ |
568 | c->IntType = req->IntType; | 510 | c->IntType = req->IntType; |
@@ -651,7 +593,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, | |||
651 | 593 | ||
652 | c->state |= CONFIG_LOCKED; | 594 | c->state |= CONFIG_LOCKED; |
653 | p_dev->_locked = 1; | 595 | p_dev->_locked = 1; |
654 | return CS_SUCCESS; | 596 | return 0; |
655 | } /* pcmcia_request_configuration */ | 597 | } /* pcmcia_request_configuration */ |
656 | EXPORT_SYMBOL(pcmcia_request_configuration); | 598 | EXPORT_SYMBOL(pcmcia_request_configuration); |
657 | 599 | ||
@@ -667,37 +609,48 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) | |||
667 | config_t *c; | 609 | config_t *c; |
668 | 610 | ||
669 | if (!(s->state & SOCKET_PRESENT)) | 611 | if (!(s->state & SOCKET_PRESENT)) |
670 | return CS_NO_CARD; | 612 | return -ENODEV; |
671 | 613 | ||
672 | if (!req) | 614 | if (!req) |
673 | return CS_UNSUPPORTED_MODE; | 615 | return -EINVAL; |
674 | c = p_dev->function_config; | 616 | c = p_dev->function_config; |
675 | if (c->state & CONFIG_LOCKED) | 617 | if (c->state & CONFIG_LOCKED) |
676 | return CS_CONFIGURATION_LOCKED; | 618 | return -EACCES; |
677 | if (c->state & CONFIG_IO_REQ) | 619 | if (c->state & CONFIG_IO_REQ) { |
678 | return CS_IN_USE; | 620 | ds_dbg(s, 0, "IO already configured\n"); |
679 | if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) | 621 | return -EBUSY; |
680 | return CS_BAD_ATTRIBUTE; | 622 | } |
623 | if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) { | ||
624 | ds_dbg(s, 0, "bad attribute setting for IO region 1\n"); | ||
625 | return -EINVAL; | ||
626 | } | ||
681 | if ((req->NumPorts2 > 0) && | 627 | if ((req->NumPorts2 > 0) && |
682 | (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) | 628 | (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) { |
683 | return CS_BAD_ATTRIBUTE; | 629 | ds_dbg(s, 0, "bad attribute setting for IO region 2\n"); |
630 | return -EINVAL; | ||
631 | } | ||
684 | 632 | ||
633 | ds_dbg(s, 1, "trying to allocate resource 1\n"); | ||
685 | if (alloc_io_space(s, req->Attributes1, &req->BasePort1, | 634 | if (alloc_io_space(s, req->Attributes1, &req->BasePort1, |
686 | req->NumPorts1, req->IOAddrLines)) | 635 | req->NumPorts1, req->IOAddrLines)) { |
687 | return CS_IN_USE; | 636 | ds_dbg(s, 0, "allocation of resource 1 failed\n"); |
637 | return -EBUSY; | ||
638 | } | ||
688 | 639 | ||
689 | if (req->NumPorts2) { | 640 | if (req->NumPorts2) { |
641 | ds_dbg(s, 1, "trying to allocate resource 2\n"); | ||
690 | if (alloc_io_space(s, req->Attributes2, &req->BasePort2, | 642 | if (alloc_io_space(s, req->Attributes2, &req->BasePort2, |
691 | req->NumPorts2, req->IOAddrLines)) { | 643 | req->NumPorts2, req->IOAddrLines)) { |
644 | ds_dbg(s, 0, "allocation of resource 2 failed\n"); | ||
692 | release_io_space(s, req->BasePort1, req->NumPorts1); | 645 | release_io_space(s, req->BasePort1, req->NumPorts1); |
693 | return CS_IN_USE; | 646 | return -EBUSY; |
694 | } | 647 | } |
695 | } | 648 | } |
696 | 649 | ||
697 | c->io = *req; | 650 | c->io = *req; |
698 | c->state |= CONFIG_IO_REQ; | 651 | c->state |= CONFIG_IO_REQ; |
699 | p_dev->_io = 1; | 652 | p_dev->_io = 1; |
700 | return CS_SUCCESS; | 653 | return 0; |
701 | } /* pcmcia_request_io */ | 654 | } /* pcmcia_request_io */ |
702 | EXPORT_SYMBOL(pcmcia_request_io); | 655 | EXPORT_SYMBOL(pcmcia_request_io); |
703 | 656 | ||
@@ -723,16 +676,18 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
723 | { | 676 | { |
724 | struct pcmcia_socket *s = p_dev->socket; | 677 | struct pcmcia_socket *s = p_dev->socket; |
725 | config_t *c; | 678 | config_t *c; |
726 | int ret = CS_IN_USE, irq = 0; | 679 | int ret = -EINVAL, irq = 0; |
727 | int type; | 680 | int type; |
728 | 681 | ||
729 | if (!(s->state & SOCKET_PRESENT)) | 682 | if (!(s->state & SOCKET_PRESENT)) |
730 | return CS_NO_CARD; | 683 | return -ENODEV; |
731 | c = p_dev->function_config; | 684 | c = p_dev->function_config; |
732 | if (c->state & CONFIG_LOCKED) | 685 | if (c->state & CONFIG_LOCKED) |
733 | return CS_CONFIGURATION_LOCKED; | 686 | return -EACCES; |
734 | if (c->state & CONFIG_IRQ_REQ) | 687 | if (c->state & CONFIG_IRQ_REQ) { |
735 | return CS_IN_USE; | 688 | ds_dbg(s, 0, "IRQ already configured\n"); |
689 | return -EBUSY; | ||
690 | } | ||
736 | 691 | ||
737 | /* Decide what type of interrupt we are registering */ | 692 | /* Decide what type of interrupt we are registering */ |
738 | type = 0; | 693 | type = 0; |
@@ -795,15 +750,19 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
795 | } | 750 | } |
796 | 751 | ||
797 | if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) { | 752 | if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) { |
798 | if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance)) | 753 | ret = request_irq(irq, req->Handler, type, |
799 | return CS_IN_USE; | 754 | p_dev->devname, req->Instance); |
755 | if (ret) | ||
756 | return ret; | ||
800 | } | 757 | } |
801 | 758 | ||
802 | /* Make sure the fact the request type was overridden is passed back */ | 759 | /* Make sure the fact the request type was overridden is passed back */ |
803 | if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) { | 760 | if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) { |
804 | req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING; | 761 | req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING; |
805 | printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n"); | 762 | dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: " |
806 | printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n"); | 763 | "request for exclusive IRQ could not be fulfilled.\n"); |
764 | dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver " | ||
765 | "needs updating to supported shared IRQ lines.\n"); | ||
807 | } | 766 | } |
808 | c->irq.Attributes = req->Attributes; | 767 | c->irq.Attributes = req->Attributes; |
809 | s->irq.AssignedIRQ = req->AssignedIRQ = irq; | 768 | s->irq.AssignedIRQ = req->AssignedIRQ = irq; |
@@ -816,7 +775,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req) | |||
816 | pcmcia_used_irq[irq]++; | 775 | pcmcia_used_irq[irq]++; |
817 | #endif | 776 | #endif |
818 | 777 | ||
819 | return CS_SUCCESS; | 778 | return 0; |
820 | } /* pcmcia_request_irq */ | 779 | } /* pcmcia_request_irq */ |
821 | EXPORT_SYMBOL(pcmcia_request_irq); | 780 | EXPORT_SYMBOL(pcmcia_request_irq); |
822 | 781 | ||
@@ -834,9 +793,11 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h | |||
834 | int w; | 793 | int w; |
835 | 794 | ||
836 | if (!(s->state & SOCKET_PRESENT)) | 795 | if (!(s->state & SOCKET_PRESENT)) |
837 | return CS_NO_CARD; | 796 | return -ENODEV; |
838 | if (req->Attributes & (WIN_PAGED | WIN_SHARED)) | 797 | if (req->Attributes & (WIN_PAGED | WIN_SHARED)) { |
839 | return CS_BAD_ATTRIBUTE; | 798 | ds_dbg(s, 0, "bad attribute setting for iomem region\n"); |
799 | return -EINVAL; | ||
800 | } | ||
840 | 801 | ||
841 | /* Window size defaults to smallest available */ | 802 | /* Window size defaults to smallest available */ |
842 | if (req->Size == 0) | 803 | if (req->Size == 0) |
@@ -844,19 +805,25 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h | |||
844 | align = (((s->features & SS_CAP_MEM_ALIGN) || | 805 | align = (((s->features & SS_CAP_MEM_ALIGN) || |
845 | (req->Attributes & WIN_STRICT_ALIGN)) ? | 806 | (req->Attributes & WIN_STRICT_ALIGN)) ? |
846 | req->Size : s->map_size); | 807 | req->Size : s->map_size); |
847 | if (req->Size & (s->map_size-1)) | 808 | if (req->Size & (s->map_size-1)) { |
848 | return CS_BAD_SIZE; | 809 | ds_dbg(s, 0, "invalid map size\n"); |
810 | return -EINVAL; | ||
811 | } | ||
849 | if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || | 812 | if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || |
850 | (req->Base & (align-1))) | 813 | (req->Base & (align-1))) { |
851 | return CS_BAD_BASE; | 814 | ds_dbg(s, 0, "invalid base address\n"); |
815 | return -EINVAL; | ||
816 | } | ||
852 | if (req->Base) | 817 | if (req->Base) |
853 | align = 0; | 818 | align = 0; |
854 | 819 | ||
855 | /* Allocate system memory window */ | 820 | /* Allocate system memory window */ |
856 | for (w = 0; w < MAX_WIN; w++) | 821 | for (w = 0; w < MAX_WIN; w++) |
857 | if (!(s->state & SOCKET_WIN_REQ(w))) break; | 822 | if (!(s->state & SOCKET_WIN_REQ(w))) break; |
858 | if (w == MAX_WIN) | 823 | if (w == MAX_WIN) { |
859 | return CS_OUT_OF_RESOURCE; | 824 | ds_dbg(s, 0, "all windows are used already\n"); |
825 | return -EINVAL; | ||
826 | } | ||
860 | 827 | ||
861 | win = &s->win[w]; | 828 | win = &s->win[w]; |
862 | win->magic = WINDOW_MAGIC; | 829 | win->magic = WINDOW_MAGIC; |
@@ -867,8 +834,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h | |||
867 | if (!(s->features & SS_CAP_STATIC_MAP)) { | 834 | if (!(s->features & SS_CAP_STATIC_MAP)) { |
868 | win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align, | 835 | win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align, |
869 | (req->Attributes & WIN_MAP_BELOW_1MB), s); | 836 | (req->Attributes & WIN_MAP_BELOW_1MB), s); |
870 | if (!win->ctl.res) | 837 | if (!win->ctl.res) { |
871 | return CS_IN_USE; | 838 | ds_dbg(s, 0, "allocating mem region failed\n"); |
839 | return -EINVAL; | ||
840 | } | ||
872 | } | 841 | } |
873 | (*p_dev)->_win |= CLIENT_WIN_REQ(w); | 842 | (*p_dev)->_win |= CLIENT_WIN_REQ(w); |
874 | 843 | ||
@@ -885,8 +854,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h | |||
885 | if (req->Attributes & WIN_USE_WAIT) | 854 | if (req->Attributes & WIN_USE_WAIT) |
886 | win->ctl.flags |= MAP_USE_WAIT; | 855 | win->ctl.flags |= MAP_USE_WAIT; |
887 | win->ctl.card_start = 0; | 856 | win->ctl.card_start = 0; |
888 | if (s->ops->set_mem_map(s, &win->ctl) != 0) | 857 | if (s->ops->set_mem_map(s, &win->ctl) != 0) { |
889 | return CS_BAD_ARGS; | 858 | ds_dbg(s, 0, "failed to set memory mapping\n"); |
859 | return -EIO; | ||
860 | } | ||
890 | s->state |= SOCKET_WIN_REQ(w); | 861 | s->state |= SOCKET_WIN_REQ(w); |
891 | 862 | ||
892 | /* Return window handle */ | 863 | /* Return window handle */ |
@@ -897,7 +868,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h | |||
897 | } | 868 | } |
898 | *wh = win; | 869 | *wh = win; |
899 | 870 | ||
900 | return CS_SUCCESS; | 871 | return 0; |
901 | } /* pcmcia_request_window */ | 872 | } /* pcmcia_request_window */ |
902 | EXPORT_SYMBOL(pcmcia_request_window); | 873 | EXPORT_SYMBOL(pcmcia_request_window); |
903 | 874 | ||
@@ -909,3 +880,79 @@ void pcmcia_disable_device(struct pcmcia_device *p_dev) { | |||
909 | pcmcia_release_window(p_dev->win); | 880 | pcmcia_release_window(p_dev->win); |
910 | } | 881 | } |
911 | EXPORT_SYMBOL(pcmcia_disable_device); | 882 | EXPORT_SYMBOL(pcmcia_disable_device); |
883 | |||
884 | |||
885 | struct pcmcia_cfg_mem { | ||
886 | tuple_t tuple; | ||
887 | cisparse_t parse; | ||
888 | u8 buf[256]; | ||
889 | cistpl_cftable_entry_t dflt; | ||
890 | }; | ||
891 | |||
892 | /** | ||
893 | * pcmcia_loop_config() - loop over configuration options | ||
894 | * @p_dev: the struct pcmcia_device which we need to loop for. | ||
895 | * @conf_check: function to call for each configuration option. | ||
896 | * It gets passed the struct pcmcia_device, the CIS data | ||
897 | * describing the configuration option, and private data | ||
898 | * being passed to pcmcia_loop_config() | ||
899 | * @priv_data: private data to be passed to the conf_check function. | ||
900 | * | ||
901 | * pcmcia_loop_config() loops over all configuration options, and calls | ||
902 | * the driver-specific conf_check() for each one, checking whether | ||
903 | * it is a valid one. | ||
904 | */ | ||
905 | int pcmcia_loop_config(struct pcmcia_device *p_dev, | ||
906 | int (*conf_check) (struct pcmcia_device *p_dev, | ||
907 | cistpl_cftable_entry_t *cfg, | ||
908 | cistpl_cftable_entry_t *dflt, | ||
909 | unsigned int vcc, | ||
910 | void *priv_data), | ||
911 | void *priv_data) | ||
912 | { | ||
913 | struct pcmcia_cfg_mem *cfg_mem; | ||
914 | |||
915 | tuple_t *tuple; | ||
916 | int ret = -ENODEV; | ||
917 | unsigned int vcc; | ||
918 | |||
919 | cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL); | ||
920 | if (cfg_mem == NULL) | ||
921 | return -ENOMEM; | ||
922 | |||
923 | /* get the current Vcc setting */ | ||
924 | vcc = p_dev->socket->socket.Vcc; | ||
925 | |||
926 | tuple = &cfg_mem->tuple; | ||
927 | tuple->TupleData = cfg_mem->buf; | ||
928 | tuple->TupleDataMax = 255; | ||
929 | tuple->TupleOffset = 0; | ||
930 | tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
931 | tuple->Attributes = 0; | ||
932 | |||
933 | ret = pcmcia_get_first_tuple(p_dev, tuple); | ||
934 | while (!ret) { | ||
935 | cistpl_cftable_entry_t *cfg = &cfg_mem->parse.cftable_entry; | ||
936 | |||
937 | if (pcmcia_get_tuple_data(p_dev, tuple)) | ||
938 | goto next_entry; | ||
939 | |||
940 | if (pcmcia_parse_tuple(tuple, &cfg_mem->parse)) | ||
941 | goto next_entry; | ||
942 | |||
943 | /* default values */ | ||
944 | p_dev->conf.ConfigIndex = cfg->index; | ||
945 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) | ||
946 | cfg_mem->dflt = *cfg; | ||
947 | |||
948 | ret = conf_check(p_dev, cfg, &cfg_mem->dflt, vcc, priv_data); | ||
949 | if (!ret) | ||
950 | break; | ||
951 | |||
952 | next_entry: | ||
953 | ret = pcmcia_get_next_tuple(p_dev, tuple); | ||
954 | } | ||
955 | |||
956 | return ret; | ||
957 | } | ||
958 | EXPORT_SYMBOL(pcmcia_loop_config); | ||