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];
48 extern int ds_pc_debug;
50 #define ds_dbg(skt, lvl, fmt, arg...) do { \
51 if (ds_pc_debug >= lvl) \
52 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \
53 cs_socket_name(skt) , ## arg); \
56 #define ds_dbg(lvl, fmt, arg...) do { } while (0)
63 * Special stuff for managing IO windows, because they are scarce
66 static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
67 unsigned int *base, unsigned int num, u_int lines)
70 unsigned int try, align;
72 align = (*base) ? (lines ? 1<<lines : 0) : 1;
73 if (align && (align < num)) {
75 ds_dbg(s, 0, "odd IO request: num %#x align %#x\n",
79 while (align && (align < num)) align <<= 1;
81 if (*base & ~(align-1)) {
82 ds_dbg(s, 0, "odd IO request: base %#x align %#x\n",
86 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
87 *base = s->io_offset | (*base & 0x0fff);
90 /* Check for an already-allocated window that must conflict with
91 * what was asked for. It is a hack because it does not catch all
92 * potential conflicts, just the most obvious ones.
94 for (i = 0; i < MAX_IO_WIN; i++)
95 if ((s->io[i].res) && *base &&
96 ((s->io[i].res->start & (align-1)) == *base))
98 for (i = 0; i < MAX_IO_WIN; i++) {
100 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
102 *base = s->io[i].res->start;
103 s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
104 s->io[i].InUse = num;
108 } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
110 /* Try to extend top of window */
111 try = s->io[i].res->end + 1;
112 if ((*base == 0) || (*base == try))
113 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
114 s->io[i].res->end + num, s) == 0) {
116 s->io[i].InUse += num;
119 /* Try to extend bottom of window */
120 try = s->io[i].res->start - num;
121 if ((*base == 0) || (*base == try))
122 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
123 s->io[i].res->end, s) == 0) {
125 s->io[i].InUse += num;
129 return (i == MAX_IO_WIN);
130 } /* alloc_io_space */
133 static void release_io_space(struct pcmcia_socket *s, unsigned int base,
138 for (i = 0; i < MAX_IO_WIN; i++) {
141 if ((s->io[i].res->start <= base) &&
142 (s->io[i].res->end >= base+num-1)) {
143 s->io[i].InUse -= num;
144 /* Free the window if no one else is using it */
145 if (s->io[i].InUse == 0) {
146 release_resource(s->io[i].res);
152 } /* release_io_space */
155 /** pccard_access_configuration_register
157 * Access_configuration_register() reads and writes configuration
158 * registers in attribute memory. Memory window 0 is reserved for
159 * this and the tuple reading services.
162 int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
165 struct pcmcia_socket *s;
170 if (!p_dev || !p_dev->function_config)
174 c = p_dev->function_config;
176 if (!(c->state & CONFIG_LOCKED))
177 return CS_CONFIGURATION_LOCKED;
179 addr = (c->ConfigBase + reg->Offset) >> 1;
181 switch (reg->Action) {
183 pcmcia_read_cis_mem(s, 1, addr, 1, &val);
188 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
195 } /* pcmcia_access_configuration_register */
196 EXPORT_SYMBOL(pcmcia_access_configuration_register);
199 int pccard_get_configuration_info(struct pcmcia_socket *s,
200 struct pcmcia_device *p_dev,
201 config_info_t *config)
205 if (!(s->state & SOCKET_PRESENT))
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;
222 config->BasePort1 = s->io[0].res->start;
223 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
231 c = p_dev->function_config;
232 config->Function = p_dev->func;
235 config->Function = 0;
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;
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;
267 } /* pccard_get_configuration_info */
269 int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
270 config_info_t *config)
272 return pccard_get_configuration_info(p_dev->socket, p_dev,
275 EXPORT_SYMBOL(pcmcia_get_configuration_info);
278 /** pcmcia_get_window
280 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
281 int idx, win_req_t *req)
286 if (!s || !(s->state & SOCKET_PRESENT))
288 for (w = idx; w < MAX_WIN; w++)
289 if (s->state & SOCKET_WIN_REQ(w))
292 return CS_NO_MORE_ITEMS;
294 req->Base = win->ctl.res->start;
295 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
296 req->AccessSpeed = win->ctl.speed;
298 if (win->ctl.flags & MAP_ATTRIB)
299 req->Attributes |= WIN_MEMORY_TYPE_AM;
300 if (win->ctl.flags & MAP_ACTIVE)
301 req->Attributes |= WIN_ENABLE;
302 if (win->ctl.flags & MAP_16BIT)
303 req->Attributes |= WIN_DATA_WIDTH_16;
304 if (win->ctl.flags & MAP_USE_WAIT)
305 req->Attributes |= WIN_USE_WAIT;
308 } /* pcmcia_get_window */
309 EXPORT_SYMBOL(pcmcia_get_window);
312 /** pcmcia_get_mem_page
314 * Change the card address of an already open memory window.
316 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
318 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
319 return CS_BAD_HANDLE;
321 req->CardOffset = win->ctl.card_start;
323 } /* pcmcia_get_mem_page */
324 EXPORT_SYMBOL(pcmcia_get_mem_page);
327 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
329 struct pcmcia_socket *s;
330 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
331 return CS_BAD_HANDLE;
335 win->ctl.card_start = req->CardOffset;
336 if (s->ops->set_mem_map(s, &win->ctl) != 0)
337 return CS_BAD_OFFSET;
339 } /* pcmcia_map_mem_page */
340 EXPORT_SYMBOL(pcmcia_map_mem_page);
343 /** pcmcia_modify_configuration
345 * Modify a locked socket configuration
347 int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
350 struct pcmcia_socket *s;
354 c = p_dev->function_config;
356 if (!(s->state & SOCKET_PRESENT))
358 if (!(c->state & CONFIG_LOCKED))
359 return CS_CONFIGURATION_LOCKED;
361 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
362 if (mod->Attributes & CONF_ENABLE_IRQ) {
363 c->Attributes |= CONF_ENABLE_IRQ;
364 s->socket.io_irq = s->irq.AssignedIRQ;
366 c->Attributes &= ~CONF_ENABLE_IRQ;
367 s->socket.io_irq = 0;
369 s->ops->set_socket(s, &s->socket);
372 if (mod->Attributes & CONF_VCC_CHANGE_VALID)
375 /* We only allow changing Vpp1 and Vpp2 to the same value */
376 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
377 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
378 if (mod->Vpp1 != mod->Vpp2)
380 s->socket.Vpp = mod->Vpp1;
381 if (s->ops->set_socket(s, &s->socket))
383 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
384 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
387 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
388 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
392 io_on.speed = io_speed;
393 for (i = 0; i < MAX_IO_WIN; i++) {
399 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
400 io_on.start = s->io[i].res->start;
401 io_on.stop = s->io[i].res->end;
403 s->ops->set_io_map(s, &io_off);
405 s->ops->set_io_map(s, &io_on);
410 } /* modify_configuration */
411 EXPORT_SYMBOL(pcmcia_modify_configuration);
414 int pcmcia_release_configuration(struct pcmcia_device *p_dev)
416 pccard_io_map io = { 0, 0, 0, 0, 1 };
417 struct pcmcia_socket *s = p_dev->socket;
418 config_t *c = p_dev->function_config;
421 if (p_dev->_locked) {
423 if (--(s->lock_count) == 0) {
424 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
426 s->socket.io_irq = 0;
427 s->ops->set_socket(s, &s->socket);
430 if (c->state & CONFIG_LOCKED) {
431 c->state &= ~CONFIG_LOCKED;
432 if (c->state & CONFIG_IO_REQ)
433 for (i = 0; i < MAX_IO_WIN; i++) {
437 if (s->io[i].Config != 0)
440 s->ops->set_io_map(s, &io);
445 } /* pcmcia_release_configuration */
448 /** pcmcia_release_io
450 * Release_io() releases the I/O ranges allocated by a client. This
451 * may be invoked some time after a card ejection has already dumped
452 * the actual socket configuration, so if the client is "stale", we
453 * don't bother checking the port ranges against the current socket
456 static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
458 struct pcmcia_socket *s = p_dev->socket;
459 config_t *c = p_dev->function_config;
462 return CS_BAD_HANDLE;
466 if ((c->io.BasePort1 != req->BasePort1) ||
467 (c->io.NumPorts1 != req->NumPorts1) ||
468 (c->io.BasePort2 != req->BasePort2) ||
469 (c->io.NumPorts2 != req->NumPorts2))
472 c->state &= ~CONFIG_IO_REQ;
474 release_io_space(s, req->BasePort1, req->NumPorts1);
476 release_io_space(s, req->BasePort2, req->NumPorts2);
479 } /* pcmcia_release_io */
482 static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
484 struct pcmcia_socket *s = p_dev->socket;
485 config_t *c= p_dev->function_config;
488 return CS_BAD_HANDLE;
491 if (c->state & CONFIG_LOCKED)
492 return CS_CONFIGURATION_LOCKED;
493 if (c->irq.Attributes != req->Attributes)
494 return CS_BAD_ATTRIBUTE;
495 if (s->irq.AssignedIRQ != req->AssignedIRQ)
497 if (--s->irq.Config == 0) {
498 c->state &= ~CONFIG_IRQ_REQ;
499 s->irq.AssignedIRQ = 0;
502 if (req->Attributes & IRQ_HANDLE_PRESENT) {
503 free_irq(req->AssignedIRQ, req->Instance);
506 #ifdef CONFIG_PCMCIA_PROBE
507 pcmcia_used_irq[req->AssignedIRQ]--;
511 } /* pcmcia_release_irq */
514 int pcmcia_release_window(window_handle_t win)
516 struct pcmcia_socket *s;
518 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
519 return CS_BAD_HANDLE;
521 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
522 return CS_BAD_HANDLE;
524 /* Shut down memory window */
525 win->ctl.flags &= ~MAP_ACTIVE;
526 s->ops->set_mem_map(s, &win->ctl);
527 s->state &= ~SOCKET_WIN_REQ(win->index);
529 /* Release system memory */
531 release_resource(win->ctl.res);
535 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
540 } /* pcmcia_release_window */
541 EXPORT_SYMBOL(pcmcia_release_window);
544 int pcmcia_request_configuration(struct pcmcia_device *p_dev,
549 struct pcmcia_socket *s = p_dev->socket;
553 if (!(s->state & SOCKET_PRESENT))
556 if (req->IntType & INT_CARDBUS)
557 return CS_UNSUPPORTED_MODE;
558 c = p_dev->function_config;
559 if (c->state & CONFIG_LOCKED)
560 return CS_CONFIGURATION_LOCKED;
562 /* Do power control. We don't allow changes in Vcc. */
563 s->socket.Vpp = req->Vpp;
564 if (s->ops->set_socket(s, &s->socket))
567 /* Pick memory or I/O card, DMA mode, interrupt */
568 c->IntType = req->IntType;
569 c->Attributes = req->Attributes;
570 if (req->IntType & INT_MEMORY_AND_IO)
571 s->socket.flags |= SS_IOCARD;
572 if (req->IntType & INT_ZOOMED_VIDEO)
573 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
574 if (req->Attributes & CONF_ENABLE_DMA)
575 s->socket.flags |= SS_DMA_MODE;
576 if (req->Attributes & CONF_ENABLE_SPKR)
577 s->socket.flags |= SS_SPKR_ENA;
578 if (req->Attributes & CONF_ENABLE_IRQ)
579 s->socket.io_irq = s->irq.AssignedIRQ;
581 s->socket.io_irq = 0;
582 s->ops->set_socket(s, &s->socket);
585 /* Set up CIS configuration registers */
586 base = c->ConfigBase = req->ConfigBase;
587 c->CardValues = req->Present;
588 if (req->Present & PRESENT_COPY) {
590 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
592 if (req->Present & PRESENT_OPTION) {
593 if (s->functions == 1) {
594 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
596 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
597 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
598 if (req->Present & PRESENT_IOBASE_0)
599 c->Option |= COR_ADDR_DECODE;
601 if (c->state & CONFIG_IRQ_REQ)
602 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
603 c->Option |= COR_LEVEL_REQ;
604 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
607 if (req->Present & PRESENT_STATUS) {
608 c->Status = req->Status;
609 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
611 if (req->Present & PRESENT_PIN_REPLACE) {
613 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
615 if (req->Present & PRESENT_EXT_STATUS) {
616 c->ExtStatus = req->ExtStatus;
617 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
619 if (req->Present & PRESENT_IOBASE_0) {
620 u_char b = c->io.BasePort1 & 0xff;
621 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
622 b = (c->io.BasePort1 >> 8) & 0xff;
623 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
625 if (req->Present & PRESENT_IOSIZE) {
626 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
627 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
630 /* Configure I/O windows */
631 if (c->state & CONFIG_IO_REQ) {
632 iomap.speed = io_speed;
633 for (i = 0; i < MAX_IO_WIN; i++)
636 iomap.flags = MAP_ACTIVE;
637 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
638 case IO_DATA_PATH_WIDTH_16:
639 iomap.flags |= MAP_16BIT; break;
640 case IO_DATA_PATH_WIDTH_AUTO:
641 iomap.flags |= MAP_AUTOSZ; break;
645 iomap.start = s->io[i].res->start;
646 iomap.stop = s->io[i].res->end;
647 s->ops->set_io_map(s, &iomap);
652 c->state |= CONFIG_LOCKED;
655 } /* pcmcia_request_configuration */
656 EXPORT_SYMBOL(pcmcia_request_configuration);
659 /** pcmcia_request_io
661 * Request_io() reserves ranges of port addresses for a socket.
662 * I have not implemented range sharing or alias addressing.
664 int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
666 struct pcmcia_socket *s = p_dev->socket;
669 if (!(s->state & SOCKET_PRESENT))
673 return CS_UNSUPPORTED_MODE;
674 c = p_dev->function_config;
675 if (c->state & CONFIG_LOCKED)
676 return CS_CONFIGURATION_LOCKED;
677 if (c->state & CONFIG_IO_REQ)
679 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
680 return CS_BAD_ATTRIBUTE;
681 if ((req->NumPorts2 > 0) &&
682 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
683 return CS_BAD_ATTRIBUTE;
685 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
686 req->NumPorts1, req->IOAddrLines))
689 if (req->NumPorts2) {
690 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
691 req->NumPorts2, req->IOAddrLines)) {
692 release_io_space(s, req->BasePort1, req->NumPorts1);
698 c->state |= CONFIG_IO_REQ;
701 } /* pcmcia_request_io */
702 EXPORT_SYMBOL(pcmcia_request_io);
705 /** pcmcia_request_irq
707 * Request_irq() reserves an irq for this client.
709 * Also, since Linux only reserves irq's when they are actually
710 * hooked, we don't guarantee that an irq will still be available
711 * when the configuration is locked. Now that I think about it,
712 * there might be a way to fix this using a dummy handler.
715 #ifdef CONFIG_PCMCIA_PROBE
716 static irqreturn_t test_action(int cpl, void *dev_id)
722 int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
724 struct pcmcia_socket *s = p_dev->socket;
726 int ret = CS_IN_USE, irq = 0;
729 if (!(s->state & SOCKET_PRESENT))
731 c = p_dev->function_config;
732 if (c->state & CONFIG_LOCKED)
733 return CS_CONFIGURATION_LOCKED;
734 if (c->state & CONFIG_IRQ_REQ)
737 /* Decide what type of interrupt we are registering */
739 if (s->functions > 1) /* All of this ought to be handled higher up */
741 if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
744 #ifdef CONFIG_PCMCIA_PROBE
747 /* if the underlying IRQ infrastructure allows for it, only allocate
748 * the IRQ, but do not enable it
750 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
751 type |= IRQ_NOAUTOEN;
752 #endif /* IRQ_NOAUTOEN */
754 if (s->irq.AssignedIRQ != 0) {
755 /* If the interrupt is already assigned, it must be the same */
756 irq = s->irq.AssignedIRQ;
759 u32 mask = s->irq_mask;
760 void *data = &p_dev->dev.driver; /* something unique to this device */
762 for (try = 0; try < 64; try++) {
765 /* marked as available by driver, and not blocked by userspace? */
766 if (!((mask >> irq) & 1))
769 /* avoid an IRQ which is already used by a PCMCIA card */
770 if ((try < 32) && pcmcia_used_irq[irq])
773 /* register the correct driver, if possible, of check whether
774 * registering a dummy handle works, i.e. if the IRQ isn't
775 * marked as used by the kernel resource management core */
776 ret = request_irq(irq,
777 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
780 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
782 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
789 /* only assign PCI irq if no IRQ already assigned */
790 if (ret && !s->irq.AssignedIRQ) {
797 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
798 if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance))
802 /* Make sure the fact the request type was overridden is passed back */
803 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
804 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
805 printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n");
806 printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n");
808 c->irq.Attributes = req->Attributes;
809 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
812 c->state |= CONFIG_IRQ_REQ;
815 #ifdef CONFIG_PCMCIA_PROBE
816 pcmcia_used_irq[irq]++;
820 } /* pcmcia_request_irq */
821 EXPORT_SYMBOL(pcmcia_request_irq);
824 /** pcmcia_request_window
826 * Request_window() establishes a mapping between card memory space
827 * and system memory space.
829 int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh)
831 struct pcmcia_socket *s = (*p_dev)->socket;
836 if (!(s->state & SOCKET_PRESENT))
838 if (req->Attributes & (WIN_PAGED | WIN_SHARED))
839 return CS_BAD_ATTRIBUTE;
841 /* Window size defaults to smallest available */
843 req->Size = s->map_size;
844 align = (((s->features & SS_CAP_MEM_ALIGN) ||
845 (req->Attributes & WIN_STRICT_ALIGN)) ?
846 req->Size : s->map_size);
847 if (req->Size & (s->map_size-1))
849 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
850 (req->Base & (align-1)))
855 /* Allocate system memory window */
856 for (w = 0; w < MAX_WIN; w++)
857 if (!(s->state & SOCKET_WIN_REQ(w))) break;
859 return CS_OUT_OF_RESOURCE;
862 win->magic = WINDOW_MAGIC;
864 win->handle = *p_dev;
867 if (!(s->features & SS_CAP_STATIC_MAP)) {
868 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
869 (req->Attributes & WIN_MAP_BELOW_1MB), s);
873 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
875 /* Configure the socket controller */
878 win->ctl.speed = req->AccessSpeed;
879 if (req->Attributes & WIN_MEMORY_TYPE)
880 win->ctl.flags |= MAP_ATTRIB;
881 if (req->Attributes & WIN_ENABLE)
882 win->ctl.flags |= MAP_ACTIVE;
883 if (req->Attributes & WIN_DATA_WIDTH_16)
884 win->ctl.flags |= MAP_16BIT;
885 if (req->Attributes & WIN_USE_WAIT)
886 win->ctl.flags |= MAP_USE_WAIT;
887 win->ctl.card_start = 0;
888 if (s->ops->set_mem_map(s, &win->ctl) != 0)
890 s->state |= SOCKET_WIN_REQ(w);
892 /* Return window handle */
893 if (s->features & SS_CAP_STATIC_MAP) {
894 req->Base = win->ctl.static_start;
896 req->Base = win->ctl.res->start;
901 } /* pcmcia_request_window */
902 EXPORT_SYMBOL(pcmcia_request_window);
904 void pcmcia_disable_device(struct pcmcia_device *p_dev) {
905 pcmcia_release_configuration(p_dev);
906 pcmcia_release_io(p_dev, &p_dev->io);
907 pcmcia_release_irq(p_dev, &p_dev->irq);
909 pcmcia_release_window(p_dev->win);
911 EXPORT_SYMBOL(pcmcia_disable_device);