]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/pcmcia/rsrc_mgr.c
pcmcia: CodingStyle fixes
[net-next-2.6.git] / drivers / pcmcia / rsrc_mgr.c
CommitLineData
1da177e4
LT
1/*
2 * rsrc_mgr.c -- Resource management routines and/or wrappers
3 *
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.
7 *
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.
11 *
12 * (C) 1999 David A. Hinds
13 */
14
1da177e4
LT
15#include <linux/module.h>
16#include <linux/kernel.h>
17
18#include <pcmcia/cs_types.h>
19#include <pcmcia/ss.h>
20#include <pcmcia/cs.h>
91284224 21#include <pcmcia/cistpl.h>
1da177e4
LT
22#include "cs_internal.h"
23
1da177e4
LT
24static int static_init(struct pcmcia_socket *s)
25{
1da177e4
LT
26 /* the good thing about SS_CAP_STATIC_MAP sockets is
27 * that they don't need a resource database */
28
1da177e4 29 s->resource_setup_done = 1;
1da177e4
LT
30
31 return 0;
32}
33
34
35struct pccard_resource_ops pccard_static_ops = {
36 .validate_mem = NULL,
37 .adjust_io_region = NULL,
38 .find_io = NULL,
39 .find_mem = NULL,
c5023801
DB
40 .add_io = NULL,
41 .add_mem = NULL,
1da177e4
LT
42 .init = static_init,
43 .exit = NULL,
44};
45EXPORT_SYMBOL(pccard_static_ops);
3b27e942
DB
46
47
48#ifdef CONFIG_PCCARD_IODYN
49
50static struct resource *
51make_resource(unsigned long b, unsigned long n, int flags, char *name)
52{
53 struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
54
55 if (res) {
56 res->name = name;
57 res->start = b;
58 res->end = b + n - 1;
59 res->flags = flags;
60 }
61 return res;
62}
63
64struct pcmcia_align_data {
65 unsigned long mask;
66 unsigned long offset;
67};
68
3b7a17fc
DB
69static resource_size_t pcmcia_align(void *align_data,
70 const struct resource *res,
b26b2d49 71 resource_size_t size, resource_size_t align)
3b27e942
DB
72{
73 struct pcmcia_align_data *data = align_data;
b26b2d49 74 resource_size_t start;
3b27e942
DB
75
76 start = (res->start & ~data->mask) + data->offset;
77 if (start < res->start)
78 start += data->mask + 1;
3b27e942
DB
79
80#ifdef CONFIG_X86
9fea84f4 81 if (res->flags & IORESOURCE_IO) {
6e83ee07 82 if (start & 0x300)
9fea84f4 83 start = (start + 0x3ff) & ~0x3ff;
9fea84f4 84 }
3b27e942
DB
85#endif
86
87#ifdef CONFIG_M68K
9fea84f4 88 if (res->flags & IORESOURCE_IO) {
3b27e942 89 if ((res->start + size - 1) >= 1024)
b26b2d49 90 start = res->end;
3b27e942
DB
91 }
92#endif
b26b2d49
DB
93
94 return start;
3b27e942
DB
95}
96
97
98static int iodyn_adjust_io_region(struct resource *res, unsigned long r_start,
99 unsigned long r_end, struct pcmcia_socket *s)
100{
101 return adjust_resource(res, r_start, r_end - r_start + 1);
102}
103
104
105static struct resource *iodyn_find_io_region(unsigned long base, int num,
106 unsigned long align, struct pcmcia_socket *s)
107{
108 struct resource *res = make_resource(0, num, IORESOURCE_IO,
f2fecec5 109 dev_name(&s->dev));
3b27e942
DB
110 struct pcmcia_align_data data;
111 unsigned long min = base;
112 int ret;
113
114 if (align == 0)
115 align = 0x10000;
116
117 data.mask = align - 1;
118 data.offset = base & data.mask;
119
120#ifdef CONFIG_PCI
121 if (s->cb_dev) {
122 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
123 min, 0, pcmcia_align, &data);
124 } else
125#endif
126 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
127 1, pcmcia_align, &data);
128
129 if (ret != 0) {
130 kfree(res);
131 res = NULL;
132 }
133 return res;
134}
135
136struct pccard_resource_ops pccard_iodyn_ops = {
137 .validate_mem = NULL,
138 .adjust_io_region = iodyn_adjust_io_region,
139 .find_io = iodyn_find_io_region,
140 .find_mem = NULL,
c5023801
DB
141 .add_io = NULL,
142 .add_mem = NULL,
3b27e942
DB
143 .init = static_init,
144 .exit = NULL,
145};
146EXPORT_SYMBOL(pccard_iodyn_ops);
147
148#endif /* CONFIG_PCCARD_IODYN */