2 * rsrc_mgr.c -- Resource management routines and/or wrappers
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
12 * (C) 1999 David A. Hinds
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
19 #include <pcmcia/cs_types.h>
20 #include <pcmcia/ss.h>
21 #include <pcmcia/cs.h>
22 #include <pcmcia/cistpl.h>
23 #include "cs_internal.h"
25 static int static_init(struct pcmcia_socket
*s
)
27 /* the good thing about SS_CAP_STATIC_MAP sockets is
28 * that they don't need a resource database */
30 s
->resource_setup_done
= 1;
36 struct pccard_resource_ops pccard_static_ops
= {
38 .adjust_io_region
= NULL
,
46 EXPORT_SYMBOL(pccard_static_ops
);
49 #ifdef CONFIG_PCCARD_IODYN
51 static struct resource
*
52 make_resource(unsigned long b
, unsigned long n
, int flags
, char *name
)
54 struct resource
*res
= kzalloc(sizeof(*res
), GFP_KERNEL
);
65 struct pcmcia_align_data
{
70 static resource_size_t
pcmcia_align(void *align_data
,
71 const struct resource
*res
,
72 resource_size_t size
, resource_size_t align
)
74 struct pcmcia_align_data
*data
= align_data
;
75 resource_size_t start
;
77 start
= (res
->start
& ~data
->mask
) + data
->offset
;
78 if (start
< res
->start
)
79 start
+= data
->mask
+ 1;
82 if (res
->flags
& IORESOURCE_IO
) {
84 start
= (start
+ 0x3ff) & ~0x3ff;
89 if (res
->flags
& IORESOURCE_IO
) {
90 if ((res
->start
+ size
- 1) >= 1024)
99 static int iodyn_adjust_io_region(struct resource
*res
, unsigned long r_start
,
100 unsigned long r_end
, struct pcmcia_socket
*s
)
102 return adjust_resource(res
, r_start
, r_end
- r_start
+ 1);
106 static struct resource
*iodyn_find_io_region(unsigned long base
, int num
,
107 unsigned long align
, struct pcmcia_socket
*s
)
109 struct resource
*res
= make_resource(0, num
, IORESOURCE_IO
,
111 struct pcmcia_align_data data
;
112 unsigned long min
= base
;
118 data
.mask
= align
- 1;
119 data
.offset
= base
& data
.mask
;
123 ret
= pci_bus_alloc_resource(s
->cb_dev
->bus
, res
, num
, 1,
124 min
, 0, pcmcia_align
, &data
);
127 ret
= allocate_resource(&ioport_resource
, res
, num
, min
, ~0UL,
128 1, pcmcia_align
, &data
);
137 struct pccard_resource_ops pccard_iodyn_ops
= {
138 .validate_mem
= NULL
,
139 .adjust_io_region
= iodyn_adjust_io_region
,
140 .find_io
= iodyn_find_io_region
,
147 EXPORT_SYMBOL(pccard_iodyn_ops
);
149 #endif /* CONFIG_PCCARD_IODYN */