2 * PCMCIA 16-bit resource management functions
4 * The initial developer of the original code is David A. Hinds
5 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2005 Dominik Brodowski
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
21 #include <linux/pci.h>
22 #include <linux/device.h>
24 #include <pcmcia/cs_types.h>
25 #include <pcmcia/ss.h>
26 #include <pcmcia/cs.h>
27 #include <pcmcia/cistpl.h>
28 #include <pcmcia/cisreg.h>
29 #include <pcmcia/ds.h>
31 #include "cs_internal.h"
32 #include "ds_internal.h"
35 /* Access speed for IO windows */
36 static int io_speed = 0;
37 module_param(io_speed, int, 0444);
40 #ifdef CONFIG_PCMCIA_PROBE
42 /* mask of IRQs already reserved by other cards, we should avoid using them */
43 static u8 pcmcia_used_irq[NR_IRQS];
47 #ifdef CONFIG_PCMCIA_DEBUG
48 extern int ds_pc_debug;
50 #define ds_dbg(skt, lvl, fmt, arg...) do { \
51 if (ds_pc_debug >= lvl) \
52 dev_printk(KERN_DEBUG, &skt->dev, \
53 "pcmcia_resource: " fmt, \
57 #define ds_dbg(skt, lvl, fmt, arg...) do { } while (0)
64 * Special stuff for managing IO windows, because they are scarce
67 static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
68 unsigned int *base, unsigned int num, u_int lines)
71 unsigned int try, align;
73 align = (*base) ? (lines ? 1<<lines : 0) : 1;
74 if (align && (align < num)) {
76 ds_dbg(s, 0, "odd IO request: num %#x align %#x\n",
80 while (align && (align < num)) align <<= 1;
82 if (*base & ~(align-1)) {
83 ds_dbg(s, 0, "odd IO request: base %#x align %#x\n",
87 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
88 *base = s->io_offset | (*base & 0x0fff);
91 /* Check for an already-allocated window that must conflict with
92 * what was asked for. It is a hack because it does not catch all
93 * potential conflicts, just the most obvious ones.
95 for (i = 0; i < MAX_IO_WIN; i++)
96 if ((s->io[i].res) && *base &&
97 ((s->io[i].res->start & (align-1)) == *base))
99 for (i = 0; i < MAX_IO_WIN; i++) {
101 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
103 *base = s->io[i].res->start;
104 s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
105 s->io[i].InUse = num;
109 } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
111 /* Try to extend top of window */
112 try = s->io[i].res->end + 1;
113 if ((*base == 0) || (*base == try))
114 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
115 s->io[i].res->end + num, s) == 0) {
117 s->io[i].InUse += num;
120 /* Try to extend bottom of window */
121 try = s->io[i].res->start - num;
122 if ((*base == 0) || (*base == try))
123 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
124 s->io[i].res->end, s) == 0) {
126 s->io[i].InUse += num;
130 return (i == MAX_IO_WIN);
131 } /* alloc_io_space */
134 static void release_io_space(struct pcmcia_socket *s, unsigned int base,
139 for (i = 0; i < MAX_IO_WIN; i++) {
142 if ((s->io[i].res->start <= base) &&
143 (s->io[i].res->end >= base+num-1)) {
144 s->io[i].InUse -= num;
145 /* Free the window if no one else is using it */
146 if (s->io[i].InUse == 0) {
147 release_resource(s->io[i].res);
153 } /* release_io_space */
156 /** pccard_access_configuration_register
158 * Access_configuration_register() reads and writes configuration
159 * registers in attribute memory. Memory window 0 is reserved for
160 * this and the tuple reading services.
163 int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
166 struct pcmcia_socket *s;
171 if (!p_dev || !p_dev->function_config)
175 c = p_dev->function_config;
177 if (!(c->state & CONFIG_LOCKED))
178 return CS_CONFIGURATION_LOCKED;
180 addr = (c->ConfigBase + reg->Offset) >> 1;
182 switch (reg->Action) {
184 pcmcia_read_cis_mem(s, 1, addr, 1, &val);
189 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
196 } /* pcmcia_access_configuration_register */
197 EXPORT_SYMBOL(pcmcia_access_configuration_register);
200 int pccard_get_configuration_info(struct pcmcia_socket *s,
201 struct pcmcia_device *p_dev,
202 config_info_t *config)
206 if (!(s->state & SOCKET_PRESENT))
210 #ifdef CONFIG_CARDBUS
211 if (s->state & SOCKET_CARDBUS) {
212 memset(config, 0, sizeof(config_info_t));
213 config->Vcc = s->socket.Vcc;
214 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
215 config->Option = s->cb_dev->subordinate->number;
216 if (s->state & SOCKET_CARDBUS_CONFIG) {
217 config->Attributes = CONF_VALID_CLIENT;
218 config->IntType = INT_CARDBUS;
219 config->AssignedIRQ = s->irq.AssignedIRQ;
220 if (config->AssignedIRQ)
221 config->Attributes |= CONF_ENABLE_IRQ;
223 config->BasePort1 = s->io[0].res->start;
224 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
232 c = p_dev->function_config;
233 config->Function = p_dev->func;
236 config->Function = 0;
239 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
240 config->Attributes = 0;
241 config->Vcc = s->socket.Vcc;
242 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
246 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
247 config->Vcc = s->socket.Vcc;
248 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
249 config->IntType = c->IntType;
250 config->ConfigBase = c->ConfigBase;
251 config->Status = c->Status;
252 config->Pin = c->Pin;
253 config->Copy = c->Copy;
254 config->Option = c->Option;
255 config->ExtStatus = c->ExtStatus;
256 config->Present = config->CardValues = c->CardValues;
257 config->IRQAttributes = c->irq.Attributes;
258 config->AssignedIRQ = s->irq.AssignedIRQ;
259 config->BasePort1 = c->io.BasePort1;
260 config->NumPorts1 = c->io.NumPorts1;
261 config->Attributes1 = c->io.Attributes1;
262 config->BasePort2 = c->io.BasePort2;
263 config->NumPorts2 = c->io.NumPorts2;
264 config->Attributes2 = c->io.Attributes2;
265 config->IOAddrLines = c->io.IOAddrLines;
268 } /* pccard_get_configuration_info */
270 int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
271 config_info_t *config)
273 return pccard_get_configuration_info(p_dev->socket, p_dev,
276 EXPORT_SYMBOL(pcmcia_get_configuration_info);
279 /** pcmcia_get_window
281 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
282 int idx, win_req_t *req)
287 if (!s || !(s->state & SOCKET_PRESENT))
289 for (w = idx; w < MAX_WIN; w++)
290 if (s->state & SOCKET_WIN_REQ(w))
293 return CS_NO_MORE_ITEMS;
295 req->Base = win->ctl.res->start;
296 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
297 req->AccessSpeed = win->ctl.speed;
299 if (win->ctl.flags & MAP_ATTRIB)
300 req->Attributes |= WIN_MEMORY_TYPE_AM;
301 if (win->ctl.flags & MAP_ACTIVE)
302 req->Attributes |= WIN_ENABLE;
303 if (win->ctl.flags & MAP_16BIT)
304 req->Attributes |= WIN_DATA_WIDTH_16;
305 if (win->ctl.flags & MAP_USE_WAIT)
306 req->Attributes |= WIN_USE_WAIT;
309 } /* pcmcia_get_window */
310 EXPORT_SYMBOL(pcmcia_get_window);
313 /** pcmcia_get_mem_page
315 * Change the card address of an already open memory window.
317 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
319 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
320 return CS_BAD_HANDLE;
322 req->CardOffset = win->ctl.card_start;
324 } /* pcmcia_get_mem_page */
325 EXPORT_SYMBOL(pcmcia_get_mem_page);
328 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
330 struct pcmcia_socket *s;
331 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
332 return CS_BAD_HANDLE;
336 win->ctl.card_start = req->CardOffset;
337 if (s->ops->set_mem_map(s, &win->ctl) != 0)
338 return CS_BAD_OFFSET;
340 } /* pcmcia_map_mem_page */
341 EXPORT_SYMBOL(pcmcia_map_mem_page);
344 /** pcmcia_modify_configuration
346 * Modify a locked socket configuration
348 int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
351 struct pcmcia_socket *s;
355 c = p_dev->function_config;
357 if (!(s->state & SOCKET_PRESENT))
359 if (!(c->state & CONFIG_LOCKED))
360 return CS_CONFIGURATION_LOCKED;
362 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
363 if (mod->Attributes & CONF_ENABLE_IRQ) {
364 c->Attributes |= CONF_ENABLE_IRQ;
365 s->socket.io_irq = s->irq.AssignedIRQ;
367 c->Attributes &= ~CONF_ENABLE_IRQ;
368 s->socket.io_irq = 0;
370 s->ops->set_socket(s, &s->socket);
373 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
376 /* We only allow changing Vpp1 and Vpp2 to the same value */
377 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
378 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
379 if (mod->Vpp1 != mod->Vpp2)
381 s->socket.Vpp = mod->Vpp1;
382 if (s->ops->set_socket(s, &s->socket))
384 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
385 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
388 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
389 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
393 io_on.speed = io_speed;
394 for (i = 0; i < MAX_IO_WIN; i++) {
400 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
401 io_on.start = s->io[i].res->start;
402 io_on.stop = s->io[i].res->end;
404 s->ops->set_io_map(s, &io_off);
406 s->ops->set_io_map(s, &io_on);
411 } /* modify_configuration */
412 EXPORT_SYMBOL(pcmcia_modify_configuration);
415 int pcmcia_release_configuration(struct pcmcia_device *p_dev)
417 pccard_io_map io = { 0, 0, 0, 0, 1 };
418 struct pcmcia_socket *s = p_dev->socket;
419 config_t *c = p_dev->function_config;
422 if (p_dev->_locked) {
424 if (--(s->lock_count) == 0) {
425 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
427 s->socket.io_irq = 0;
428 s->ops->set_socket(s, &s->socket);
431 if (c->state & CONFIG_LOCKED) {
432 c->state &= ~CONFIG_LOCKED;
433 if (c->state & CONFIG_IO_REQ)
434 for (i = 0; i < MAX_IO_WIN; i++) {
438 if (s->io[i].Config != 0)
441 s->ops->set_io_map(s, &io);
446 } /* pcmcia_release_configuration */
449 /** pcmcia_release_io
451 * Release_io() releases the I/O ranges allocated by a client. This
452 * may be invoked some time after a card ejection has already dumped
453 * the actual socket configuration, so if the client is "stale", we
454 * don't bother checking the port ranges against the current socket
457 static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
459 struct pcmcia_socket *s = p_dev->socket;
460 config_t *c = p_dev->function_config;
463 return CS_BAD_HANDLE;
467 if ((c->io.BasePort1 != req->BasePort1) ||
468 (c->io.NumPorts1 != req->NumPorts1) ||
469 (c->io.BasePort2 != req->BasePort2) ||
470 (c->io.NumPorts2 != req->NumPorts2))
473 c->state &= ~CONFIG_IO_REQ;
475 release_io_space(s, req->BasePort1, req->NumPorts1);
477 release_io_space(s, req->BasePort2, req->NumPorts2);
480 } /* pcmcia_release_io */
483 static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
485 struct pcmcia_socket *s = p_dev->socket;
486 config_t *c= p_dev->function_config;
489 return CS_BAD_HANDLE;
492 if (c->state & CONFIG_LOCKED)
493 return CS_CONFIGURATION_LOCKED;
494 if (c->irq.Attributes != req->Attributes)
495 return CS_BAD_ATTRIBUTE;
496 if (s->irq.AssignedIRQ != req->AssignedIRQ)
498 if (--s->irq.Config == 0) {
499 c->state &= ~CONFIG_IRQ_REQ;
500 s->irq.AssignedIRQ = 0;
503 if (req->Attributes & IRQ_HANDLE_PRESENT) {
504 free_irq(req->AssignedIRQ, req->Instance);
507 #ifdef CONFIG_PCMCIA_PROBE
508 pcmcia_used_irq[req->AssignedIRQ]--;
512 } /* pcmcia_release_irq */
515 int pcmcia_release_window(window_handle_t win)
517 struct pcmcia_socket *s;
519 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
520 return CS_BAD_HANDLE;
522 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
523 return CS_BAD_HANDLE;
525 /* Shut down memory window */
526 win->ctl.flags &= ~MAP_ACTIVE;
527 s->ops->set_mem_map(s, &win->ctl);
528 s->state &= ~SOCKET_WIN_REQ(win->index);
530 /* Release system memory */
532 release_resource(win->ctl.res);
536 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
541 } /* pcmcia_release_window */
542 EXPORT_SYMBOL(pcmcia_release_window);
545 int pcmcia_request_configuration(struct pcmcia_device *p_dev,
550 struct pcmcia_socket *s = p_dev->socket;
554 if (!(s->state & SOCKET_PRESENT))
557 if (req->IntType & INT_CARDBUS)
558 return CS_UNSUPPORTED_MODE;
559 c = p_dev->function_config;
560 if (c->state & CONFIG_LOCKED)
561 return CS_CONFIGURATION_LOCKED;
563 /* Do power control. We don't allow changes in Vcc. */
564 s->socket.Vpp = req->Vpp;
565 if (s->ops->set_socket(s, &s->socket))
568 /* Pick memory or I/O card, DMA mode, interrupt */
569 c->IntType = req->IntType;
570 c->Attributes = req->Attributes;
571 if (req->IntType & INT_MEMORY_AND_IO)
572 s->socket.flags |= SS_IOCARD;
573 if (req->IntType & INT_ZOOMED_VIDEO)
574 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
575 if (req->Attributes & CONF_ENABLE_DMA)
576 s->socket.flags |= SS_DMA_MODE;
577 if (req->Attributes & CONF_ENABLE_SPKR)
578 s->socket.flags |= SS_SPKR_ENA;
579 if (req->Attributes & CONF_ENABLE_IRQ)
580 s->socket.io_irq = s->irq.AssignedIRQ;
582 s->socket.io_irq = 0;
583 s->ops->set_socket(s, &s->socket);
586 /* Set up CIS configuration registers */
587 base = c->ConfigBase = req->ConfigBase;
588 c->CardValues = req->Present;
589 if (req->Present & PRESENT_COPY) {
591 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
593 if (req->Present & PRESENT_OPTION) {
594 if (s->functions == 1) {
595 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
597 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
598 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
599 if (req->Present & PRESENT_IOBASE_0)
600 c->Option |= COR_ADDR_DECODE;
602 if (c->state & CONFIG_IRQ_REQ)
603 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
604 c->Option |= COR_LEVEL_REQ;
605 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
608 if (req->Present & PRESENT_STATUS) {
609 c->Status = req->Status;
610 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
612 if (req->Present & PRESENT_PIN_REPLACE) {
614 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
616 if (req->Present & PRESENT_EXT_STATUS) {
617 c->ExtStatus = req->ExtStatus;
618 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
620 if (req->Present & PRESENT_IOBASE_0) {
621 u_char b = c->io.BasePort1 & 0xff;
622 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
623 b = (c->io.BasePort1 >> 8) & 0xff;
624 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
626 if (req->Present & PRESENT_IOSIZE) {
627 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
628 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
631 /* Configure I/O windows */
632 if (c->state & CONFIG_IO_REQ) {
633 iomap.speed = io_speed;
634 for (i = 0; i < MAX_IO_WIN; i++)
637 iomap.flags = MAP_ACTIVE;
638 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
639 case IO_DATA_PATH_WIDTH_16:
640 iomap.flags |= MAP_16BIT; break;
641 case IO_DATA_PATH_WIDTH_AUTO:
642 iomap.flags |= MAP_AUTOSZ; break;
646 iomap.start = s->io[i].res->start;
647 iomap.stop = s->io[i].res->end;
648 s->ops->set_io_map(s, &iomap);
653 c->state |= CONFIG_LOCKED;
656 } /* pcmcia_request_configuration */
657 EXPORT_SYMBOL(pcmcia_request_configuration);
660 /** pcmcia_request_io
662 * Request_io() reserves ranges of port addresses for a socket.
663 * I have not implemented range sharing or alias addressing.
665 int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
667 struct pcmcia_socket *s = p_dev->socket;
670 if (!(s->state & SOCKET_PRESENT))
674 return CS_UNSUPPORTED_MODE;
675 c = p_dev->function_config;
676 if (c->state & CONFIG_LOCKED)
677 return CS_CONFIGURATION_LOCKED;
678 if (c->state & CONFIG_IO_REQ)
680 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
681 return CS_BAD_ATTRIBUTE;
682 if ((req->NumPorts2 > 0) &&
683 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
684 return CS_BAD_ATTRIBUTE;
686 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
687 req->NumPorts1, req->IOAddrLines))
690 if (req->NumPorts2) {
691 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
692 req->NumPorts2, req->IOAddrLines)) {
693 release_io_space(s, req->BasePort1, req->NumPorts1);
699 c->state |= CONFIG_IO_REQ;
702 } /* pcmcia_request_io */
703 EXPORT_SYMBOL(pcmcia_request_io);
706 /** pcmcia_request_irq
708 * Request_irq() reserves an irq for this client.
710 * Also, since Linux only reserves irq's when they are actually
711 * hooked, we don't guarantee that an irq will still be available
712 * when the configuration is locked. Now that I think about it,
713 * there might be a way to fix this using a dummy handler.
716 #ifdef CONFIG_PCMCIA_PROBE
717 static irqreturn_t test_action(int cpl, void *dev_id)
723 int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
725 struct pcmcia_socket *s = p_dev->socket;
727 int ret = CS_IN_USE, irq = 0;
730 if (!(s->state & SOCKET_PRESENT))
732 c = p_dev->function_config;
733 if (c->state & CONFIG_LOCKED)
734 return CS_CONFIGURATION_LOCKED;
735 if (c->state & CONFIG_IRQ_REQ)
738 /* Decide what type of interrupt we are registering */
740 if (s->functions > 1) /* All of this ought to be handled higher up */
742 if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
745 #ifdef CONFIG_PCMCIA_PROBE
748 /* if the underlying IRQ infrastructure allows for it, only allocate
749 * the IRQ, but do not enable it
751 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
752 type |= IRQ_NOAUTOEN;
753 #endif /* IRQ_NOAUTOEN */
755 if (s->irq.AssignedIRQ != 0) {
756 /* If the interrupt is already assigned, it must be the same */
757 irq = s->irq.AssignedIRQ;
760 u32 mask = s->irq_mask;
761 void *data = &p_dev->dev.driver; /* something unique to this device */
763 for (try = 0; try < 64; try++) {
766 /* marked as available by driver, and not blocked by userspace? */
767 if (!((mask >> irq) & 1))
770 /* avoid an IRQ which is already used by a PCMCIA card */
771 if ((try < 32) && pcmcia_used_irq[irq])
774 /* register the correct driver, if possible, of check whether
775 * registering a dummy handle works, i.e. if the IRQ isn't
776 * marked as used by the kernel resource management core */
777 ret = request_irq(irq,
778 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
781 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
783 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
790 /* only assign PCI irq if no IRQ already assigned */
791 if (ret && !s->irq.AssignedIRQ) {
798 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
799 if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance))
803 /* Make sure the fact the request type was overridden is passed back */
804 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
805 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
806 dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: "
807 "request for exclusive IRQ could not be fulfilled.\n");
808 dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver "
809 "needs updating to supported shared IRQ lines.\n");
811 c->irq.Attributes = req->Attributes;
812 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
815 c->state |= CONFIG_IRQ_REQ;
818 #ifdef CONFIG_PCMCIA_PROBE
819 pcmcia_used_irq[irq]++;
823 } /* pcmcia_request_irq */
824 EXPORT_SYMBOL(pcmcia_request_irq);
827 /** pcmcia_request_window
829 * Request_window() establishes a mapping between card memory space
830 * and system memory space.
832 int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh)
834 struct pcmcia_socket *s = (*p_dev)->socket;
839 if (!(s->state & SOCKET_PRESENT))
841 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
842 return CS_BAD_ATTRIBUTE;
844 /* Window size defaults to smallest available */
846 req->Size = s->map_size;
847 align = (((s->features & SS_CAP_MEM_ALIGN) ||
848 (req->Attributes & WIN_STRICT_ALIGN)) ?
849 req->Size : s->map_size);
850 if (req->Size & (s->map_size-1))
852 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
853 (req->Base & (align-1)))
858 /* Allocate system memory window */
859 for (w = 0; w < MAX_WIN; w++)
860 if (!(s->state & SOCKET_WIN_REQ(w))) break;
862 return CS_OUT_OF_RESOURCE;
865 win->magic = WINDOW_MAGIC;
867 win->handle = *p_dev;
870 if (!(s->features & SS_CAP_STATIC_MAP)) {
871 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
872 (req->Attributes & WIN_MAP_BELOW_1MB), s);
876 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
878 /* Configure the socket controller */
881 win->ctl.speed = req->AccessSpeed;
882 if (req->Attributes & WIN_MEMORY_TYPE)
883 win->ctl.flags |= MAP_ATTRIB;
884 if (req->Attributes & WIN_ENABLE)
885 win->ctl.flags |= MAP_ACTIVE;
886 if (req->Attributes & WIN_DATA_WIDTH_16)
887 win->ctl.flags |= MAP_16BIT;
888 if (req->Attributes & WIN_USE_WAIT)
889 win->ctl.flags |= MAP_USE_WAIT;
890 win->ctl.card_start = 0;
891 if (s->ops->set_mem_map(s, &win->ctl) != 0)
893 s->state |= SOCKET_WIN_REQ(w);
895 /* Return window handle */
896 if (s->features & SS_CAP_STATIC_MAP) {
897 req->Base = win->ctl.static_start;
899 req->Base = win->ctl.res->start;
904 } /* pcmcia_request_window */
905 EXPORT_SYMBOL(pcmcia_request_window);
907 void pcmcia_disable_device(struct pcmcia_device *p_dev) {
908 pcmcia_release_configuration(p_dev);
909 pcmcia_release_io(p_dev, &p_dev->io);
910 pcmcia_release_irq(p_dev, &p_dev->irq);
912 pcmcia_release_window(p_dev->win);
914 EXPORT_SYMBOL(pcmcia_disable_device);