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))
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 /** pcmcia_get_window
202 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
203 int idx, win_req_t *req)
208 if (!s || !(s->state & SOCKET_PRESENT))
210 for (w = idx; w < MAX_WIN; w++)
211 if (s->state & SOCKET_WIN_REQ(w))
216 req->Base = win->ctl.res->start;
217 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
218 req->AccessSpeed = win->ctl.speed;
220 if (win->ctl.flags & MAP_ATTRIB)
221 req->Attributes |= WIN_MEMORY_TYPE_AM;
222 if (win->ctl.flags & MAP_ACTIVE)
223 req->Attributes |= WIN_ENABLE;
224 if (win->ctl.flags & MAP_16BIT)
225 req->Attributes |= WIN_DATA_WIDTH_16;
226 if (win->ctl.flags & MAP_USE_WAIT)
227 req->Attributes |= WIN_USE_WAIT;
230 } /* pcmcia_get_window */
231 EXPORT_SYMBOL(pcmcia_get_window);
234 /** pcmcia_get_mem_page
236 * Change the card address of an already open memory window.
238 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
240 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
243 req->CardOffset = win->ctl.card_start;
245 } /* pcmcia_get_mem_page */
246 EXPORT_SYMBOL(pcmcia_get_mem_page);
249 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
251 struct pcmcia_socket *s;
252 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
255 if (req->Page != 0) {
256 ds_dbg(s, 0, "failure: requested page is zero\n");
259 win->ctl.card_start = req->CardOffset;
260 if (s->ops->set_mem_map(s, &win->ctl) != 0)
261 return CS_BAD_OFFSET;
263 } /* pcmcia_map_mem_page */
264 EXPORT_SYMBOL(pcmcia_map_mem_page);
267 /** pcmcia_modify_configuration
269 * Modify a locked socket configuration
271 int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
274 struct pcmcia_socket *s;
278 c = p_dev->function_config;
280 if (!(s->state & SOCKET_PRESENT))
282 if (!(c->state & CONFIG_LOCKED))
285 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
286 if (mod->Attributes & CONF_ENABLE_IRQ) {
287 c->Attributes |= CONF_ENABLE_IRQ;
288 s->socket.io_irq = s->irq.AssignedIRQ;
290 c->Attributes &= ~CONF_ENABLE_IRQ;
291 s->socket.io_irq = 0;
293 s->ops->set_socket(s, &s->socket);
296 if (mod->Attributes & CONF_VCC_CHANGE_VALID) {
297 ds_dbg(s, 0, "changing Vcc is not allowed at this time\n");
301 /* We only allow changing Vpp1 and Vpp2 to the same value */
302 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
303 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
304 if (mod->Vpp1 != mod->Vpp2)
305 ds_dbg(s, 0, "Vpp1 and Vpp2 must be the same\n");
307 s->socket.Vpp = mod->Vpp1;
308 if (s->ops->set_socket(s, &s->socket)) {
309 dev_printk(KERN_WARNING, &s->dev,
310 "Unable to set VPP\n");
313 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
314 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
315 ds_dbg(s, 0, "changing Vcc is not allowed at this time\n");
319 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
320 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
324 io_on.speed = io_speed;
325 for (i = 0; i < MAX_IO_WIN; i++) {
331 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
332 io_on.start = s->io[i].res->start;
333 io_on.stop = s->io[i].res->end;
335 s->ops->set_io_map(s, &io_off);
337 s->ops->set_io_map(s, &io_on);
342 } /* modify_configuration */
343 EXPORT_SYMBOL(pcmcia_modify_configuration);
346 int pcmcia_release_configuration(struct pcmcia_device *p_dev)
348 pccard_io_map io = { 0, 0, 0, 0, 1 };
349 struct pcmcia_socket *s = p_dev->socket;
350 config_t *c = p_dev->function_config;
353 if (p_dev->_locked) {
355 if (--(s->lock_count) == 0) {
356 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
358 s->socket.io_irq = 0;
359 s->ops->set_socket(s, &s->socket);
362 if (c->state & CONFIG_LOCKED) {
363 c->state &= ~CONFIG_LOCKED;
364 if (c->state & CONFIG_IO_REQ)
365 for (i = 0; i < MAX_IO_WIN; i++) {
369 if (s->io[i].Config != 0)
372 s->ops->set_io_map(s, &io);
377 } /* pcmcia_release_configuration */
380 /** pcmcia_release_io
382 * Release_io() releases the I/O ranges allocated by a client. This
383 * may be invoked some time after a card ejection has already dumped
384 * the actual socket configuration, so if the client is "stale", we
385 * don't bother checking the port ranges against the current socket
388 static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
390 struct pcmcia_socket *s = p_dev->socket;
391 config_t *c = p_dev->function_config;
398 if ((c->io.BasePort1 != req->BasePort1) ||
399 (c->io.NumPorts1 != req->NumPorts1) ||
400 (c->io.BasePort2 != req->BasePort2) ||
401 (c->io.NumPorts2 != req->NumPorts2))
404 c->state &= ~CONFIG_IO_REQ;
406 release_io_space(s, req->BasePort1, req->NumPorts1);
408 release_io_space(s, req->BasePort2, req->NumPorts2);
411 } /* pcmcia_release_io */
414 static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
416 struct pcmcia_socket *s = p_dev->socket;
417 config_t *c= p_dev->function_config;
423 if (c->state & CONFIG_LOCKED)
425 if (c->irq.Attributes != req->Attributes) {
426 ds_dbg(s, 0, "IRQ attributes must match assigned ones\n");
429 if (s->irq.AssignedIRQ != req->AssignedIRQ)
431 if (--s->irq.Config == 0) {
432 c->state &= ~CONFIG_IRQ_REQ;
433 s->irq.AssignedIRQ = 0;
436 if (req->Attributes & IRQ_HANDLE_PRESENT) {
437 free_irq(req->AssignedIRQ, req->Instance);
440 #ifdef CONFIG_PCMCIA_PROBE
441 pcmcia_used_irq[req->AssignedIRQ]--;
445 } /* pcmcia_release_irq */
448 int pcmcia_release_window(window_handle_t win)
450 struct pcmcia_socket *s;
452 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
455 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
458 /* Shut down memory window */
459 win->ctl.flags &= ~MAP_ACTIVE;
460 s->ops->set_mem_map(s, &win->ctl);
461 s->state &= ~SOCKET_WIN_REQ(win->index);
463 /* Release system memory */
465 release_resource(win->ctl.res);
469 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
474 } /* pcmcia_release_window */
475 EXPORT_SYMBOL(pcmcia_release_window);
478 int pcmcia_request_configuration(struct pcmcia_device *p_dev,
483 struct pcmcia_socket *s = p_dev->socket;
487 if (!(s->state & SOCKET_PRESENT))
490 if (req->IntType & INT_CARDBUS) {
491 ds_dbg(p_dev->socket, 0, "IntType may not be INT_CARDBUS\n");
494 c = p_dev->function_config;
495 if (c->state & CONFIG_LOCKED)
498 /* Do power control. We don't allow changes in Vcc. */
499 s->socket.Vpp = req->Vpp;
500 if (s->ops->set_socket(s, &s->socket)) {
501 dev_printk(KERN_WARNING, &s->dev,
502 "Unable to set socket state\n");
506 /* Pick memory or I/O card, DMA mode, interrupt */
507 c->IntType = req->IntType;
508 c->Attributes = req->Attributes;
509 if (req->IntType & INT_MEMORY_AND_IO)
510 s->socket.flags |= SS_IOCARD;
511 if (req->IntType & INT_ZOOMED_VIDEO)
512 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
513 if (req->Attributes & CONF_ENABLE_DMA)
514 s->socket.flags |= SS_DMA_MODE;
515 if (req->Attributes & CONF_ENABLE_SPKR)
516 s->socket.flags |= SS_SPKR_ENA;
517 if (req->Attributes & CONF_ENABLE_IRQ)
518 s->socket.io_irq = s->irq.AssignedIRQ;
520 s->socket.io_irq = 0;
521 s->ops->set_socket(s, &s->socket);
524 /* Set up CIS configuration registers */
525 base = c->ConfigBase = req->ConfigBase;
526 c->CardValues = req->Present;
527 if (req->Present & PRESENT_COPY) {
529 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
531 if (req->Present & PRESENT_OPTION) {
532 if (s->functions == 1) {
533 c->Option = req->ConfigIndex & COR_CONFIG_MASK;
535 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK;
536 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA;
537 if (req->Present & PRESENT_IOBASE_0)
538 c->Option |= COR_ADDR_DECODE;
540 if (c->state & CONFIG_IRQ_REQ)
541 if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
542 c->Option |= COR_LEVEL_REQ;
543 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
546 if (req->Present & PRESENT_STATUS) {
547 c->Status = req->Status;
548 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status);
550 if (req->Present & PRESENT_PIN_REPLACE) {
552 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin);
554 if (req->Present & PRESENT_EXT_STATUS) {
555 c->ExtStatus = req->ExtStatus;
556 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
558 if (req->Present & PRESENT_IOBASE_0) {
559 u_char b = c->io.BasePort1 & 0xff;
560 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
561 b = (c->io.BasePort1 >> 8) & 0xff;
562 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
564 if (req->Present & PRESENT_IOSIZE) {
565 u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
566 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
569 /* Configure I/O windows */
570 if (c->state & CONFIG_IO_REQ) {
571 iomap.speed = io_speed;
572 for (i = 0; i < MAX_IO_WIN; i++)
575 iomap.flags = MAP_ACTIVE;
576 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
577 case IO_DATA_PATH_WIDTH_16:
578 iomap.flags |= MAP_16BIT; break;
579 case IO_DATA_PATH_WIDTH_AUTO:
580 iomap.flags |= MAP_AUTOSZ; break;
584 iomap.start = s->io[i].res->start;
585 iomap.stop = s->io[i].res->end;
586 s->ops->set_io_map(s, &iomap);
591 c->state |= CONFIG_LOCKED;
594 } /* pcmcia_request_configuration */
595 EXPORT_SYMBOL(pcmcia_request_configuration);
598 /** pcmcia_request_io
600 * Request_io() reserves ranges of port addresses for a socket.
601 * I have not implemented range sharing or alias addressing.
603 int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
605 struct pcmcia_socket *s = p_dev->socket;
608 if (!(s->state & SOCKET_PRESENT))
613 c = p_dev->function_config;
614 if (c->state & CONFIG_LOCKED)
616 if (c->state & CONFIG_IO_REQ) {
617 ds_dbg(s, 0, "IO already configured\n");
620 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) {
621 ds_dbg(s, 0, "bad attribute setting for IO region 1\n");
624 if ((req->NumPorts2 > 0) &&
625 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) {
626 ds_dbg(s, 0, "bad attribute setting for IO region 2\n");
630 ds_dbg(s, 1, "trying to allocate resource 1\n");
631 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
632 req->NumPorts1, req->IOAddrLines)) {
633 ds_dbg(s, 0, "allocation of resource 1 failed\n");
637 if (req->NumPorts2) {
638 ds_dbg(s, 1, "trying to allocate resource 2\n");
639 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
640 req->NumPorts2, req->IOAddrLines)) {
641 ds_dbg(s, 0, "allocation of resource 2 failed\n");
642 release_io_space(s, req->BasePort1, req->NumPorts1);
648 c->state |= CONFIG_IO_REQ;
651 } /* pcmcia_request_io */
652 EXPORT_SYMBOL(pcmcia_request_io);
655 /** pcmcia_request_irq
657 * Request_irq() reserves an irq for this client.
659 * Also, since Linux only reserves irq's when they are actually
660 * hooked, we don't guarantee that an irq will still be available
661 * when the configuration is locked. Now that I think about it,
662 * there might be a way to fix this using a dummy handler.
665 #ifdef CONFIG_PCMCIA_PROBE
666 static irqreturn_t test_action(int cpl, void *dev_id)
672 int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
674 struct pcmcia_socket *s = p_dev->socket;
676 int ret = -EINVAL, irq = 0;
679 if (!(s->state & SOCKET_PRESENT))
681 c = p_dev->function_config;
682 if (c->state & CONFIG_LOCKED)
684 if (c->state & CONFIG_IRQ_REQ) {
685 ds_dbg(s, 0, "IRQ already configured\n");
689 /* Decide what type of interrupt we are registering */
691 if (s->functions > 1) /* All of this ought to be handled higher up */
693 if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
696 #ifdef CONFIG_PCMCIA_PROBE
699 /* if the underlying IRQ infrastructure allows for it, only allocate
700 * the IRQ, but do not enable it
702 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
703 type |= IRQ_NOAUTOEN;
704 #endif /* IRQ_NOAUTOEN */
706 if (s->irq.AssignedIRQ != 0) {
707 /* If the interrupt is already assigned, it must be the same */
708 irq = s->irq.AssignedIRQ;
711 u32 mask = s->irq_mask;
712 void *data = &p_dev->dev.driver; /* something unique to this device */
714 for (try = 0; try < 64; try++) {
717 /* marked as available by driver, and not blocked by userspace? */
718 if (!((mask >> irq) & 1))
721 /* avoid an IRQ which is already used by a PCMCIA card */
722 if ((try < 32) && pcmcia_used_irq[irq])
725 /* register the correct driver, if possible, of check whether
726 * registering a dummy handle works, i.e. if the IRQ isn't
727 * marked as used by the kernel resource management core */
728 ret = request_irq(irq,
729 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action,
732 (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data);
734 if (!(req->Attributes & IRQ_HANDLE_PRESENT))
741 /* only assign PCI irq if no IRQ already assigned */
742 if (ret && !s->irq.AssignedIRQ) {
749 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
750 ret = request_irq(irq, req->Handler, type,
751 p_dev->devname, req->Instance);
756 /* Make sure the fact the request type was overridden is passed back */
757 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
758 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
759 dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: "
760 "request for exclusive IRQ could not be fulfilled.\n");
761 dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver "
762 "needs updating to supported shared IRQ lines.\n");
764 c->irq.Attributes = req->Attributes;
765 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
768 c->state |= CONFIG_IRQ_REQ;
771 #ifdef CONFIG_PCMCIA_PROBE
772 pcmcia_used_irq[irq]++;
776 } /* pcmcia_request_irq */
777 EXPORT_SYMBOL(pcmcia_request_irq);
780 /** pcmcia_request_window
782 * Request_window() establishes a mapping between card memory space
783 * and system memory space.
785 int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh)
787 struct pcmcia_socket *s = (*p_dev)->socket;
792 if (!(s->state & SOCKET_PRESENT))
794 if (req->Attributes & (WIN_PAGED | WIN_SHARED)) {
795 ds_dbg(s, 0, "bad attribute setting for iomem region\n");
799 /* Window size defaults to smallest available */
801 req->Size = s->map_size;
802 align = (((s->features & SS_CAP_MEM_ALIGN) ||
803 (req->Attributes & WIN_STRICT_ALIGN)) ?
804 req->Size : s->map_size);
805 if (req->Size & (s->map_size-1))
807 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
808 (req->Base & (align-1)))
813 /* Allocate system memory window */
814 for (w = 0; w < MAX_WIN; w++)
815 if (!(s->state & SOCKET_WIN_REQ(w))) break;
817 ds_dbg(s, 0, "all windows are used already\n");
822 win->magic = WINDOW_MAGIC;
824 win->handle = *p_dev;
827 if (!(s->features & SS_CAP_STATIC_MAP)) {
828 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
829 (req->Attributes & WIN_MAP_BELOW_1MB), s);
831 ds_dbg(s, 0, "allocating mem region failed\n");
835 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
837 /* Configure the socket controller */
840 win->ctl.speed = req->AccessSpeed;
841 if (req->Attributes & WIN_MEMORY_TYPE)
842 win->ctl.flags |= MAP_ATTRIB;
843 if (req->Attributes & WIN_ENABLE)
844 win->ctl.flags |= MAP_ACTIVE;
845 if (req->Attributes & WIN_DATA_WIDTH_16)
846 win->ctl.flags |= MAP_16BIT;
847 if (req->Attributes & WIN_USE_WAIT)
848 win->ctl.flags |= MAP_USE_WAIT;
849 win->ctl.card_start = 0;
850 if (s->ops->set_mem_map(s, &win->ctl) != 0)
852 s->state |= SOCKET_WIN_REQ(w);
854 /* Return window handle */
855 if (s->features & SS_CAP_STATIC_MAP) {
856 req->Base = win->ctl.static_start;
858 req->Base = win->ctl.res->start;
863 } /* pcmcia_request_window */
864 EXPORT_SYMBOL(pcmcia_request_window);
866 void pcmcia_disable_device(struct pcmcia_device *p_dev) {
867 pcmcia_release_configuration(p_dev);
868 pcmcia_release_io(p_dev, &p_dev->io);
869 pcmcia_release_irq(p_dev, &p_dev->irq);
871 pcmcia_release_window(p_dev->win);
873 EXPORT_SYMBOL(pcmcia_disable_device);
876 struct pcmcia_cfg_mem {
880 cistpl_cftable_entry_t dflt;
884 * pcmcia_loop_config() - loop over configuration options
885 * @p_dev: the struct pcmcia_device which we need to loop for.
886 * @conf_check: function to call for each configuration option.
887 * It gets passed the struct pcmcia_device, the CIS data
888 * describing the configuration option, and private data
889 * being passed to pcmcia_loop_config()
890 * @priv_data: private data to be passed to the conf_check function.
892 * pcmcia_loop_config() loops over all configuration options, and calls
893 * the driver-specific conf_check() for each one, checking whether
896 int pcmcia_loop_config(struct pcmcia_device *p_dev,
897 int (*conf_check) (struct pcmcia_device *p_dev,
898 cistpl_cftable_entry_t *cfg,
899 cistpl_cftable_entry_t *dflt,
904 struct pcmcia_cfg_mem *cfg_mem;
910 cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
914 /* get the current Vcc setting */
915 vcc = p_dev->socket->socket.Vcc;
917 tuple = &cfg_mem->tuple;
918 tuple->TupleData = cfg_mem->buf;
919 tuple->TupleDataMax = 255;
920 tuple->TupleOffset = 0;
921 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
922 tuple->Attributes = 0;
924 ret = pcmcia_get_first_tuple(p_dev, tuple);
926 cistpl_cftable_entry_t *cfg = &cfg_mem->parse.cftable_entry;
928 if (pcmcia_get_tuple_data(p_dev, tuple))
931 if (pcmcia_parse_tuple(p_dev, tuple, &cfg_mem->parse))
935 p_dev->conf.ConfigIndex = cfg->index;
936 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
937 cfg_mem->dflt = *cfg;
939 ret = conf_check(p_dev, cfg, &cfg_mem->dflt, vcc, priv_data);
944 ret = pcmcia_get_next_tuple(p_dev, tuple);
949 EXPORT_SYMBOL(pcmcia_loop_config);