Debian Codegraph @

linux/pcmcia-cs/glue/pcmcia_glue.h

raw
1 /*
2 * pcmcia card services glue code
3 *
4 * Copyright (C) 2006 Free Software Foundation, Inc.
5 * Written by Stefan Siegl <[email protected]>.
6 *
7 * This file is part of GNU Mach.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #ifndef _PCMCIA_GLUE_H
25 #define _PCMCIA_GLUE_H
26
27 /*
28 * pcmcia glue configuration
29 */
30 #define PCMCIA_DEBUG 4
31 /* Maximum number of sockets supported by the glue code. */
32 #define MAX_SOCKS 8
33
34
35 /*
36 * Linux kernel version handling.
37 */
38 #include <linux/version.h>
39 #define UTS_VERSION "" /* Hm. */
40 #define KERNEL_VERSION(v,p,s) (((v)<<16)+(p<<8)+s)
41
42
43 /*
44 * Some cardbus drivers want `CARDBUS' to be defined.
45 */
46 #ifdef CONFIG_CARDBUS
47 #define CARDBUS 1
48 #endif
49
50
51 /*
52 * Some includes.
53 */
54 #include <linux/malloc.h>
55 #include <pcmcia/driver_ops.h>
56
57
58 /*
59 * ioremap and iounmap
60 */
61 #include <linux/pci.h>
62 #include <linux/compatmac.h>
63 #define iounmap(x) (((long)x<0x100000)?0:vfree ((void*)x))
64
65
66 /*
67 * These are implemented in rsrc_mgr.c.
68 */
69 extern int check_mem_region(u_long base, u_long num);
70 extern void request_mem_region(u_long base, u_long num, char *name);
71 extern void release_mem_region(u_long base, u_long num);
72
73
74 /*
75 * Timer and delaying functions.
76 */
77 #include <linux/delay.h>
78 #define mod_timer(a, b) \
79 do { del_timer(a); (a)->expires = (b); add_timer(a); } while (0)
80 #define mdelay(x) \
81 do { int i; for (i=0;i<x;i++) __udelay(1000); } while (0)
82
83
84 /*
85 * GNU Mach's Linux glue code doesn't have
86 * `interruptible_sleep_on_timeout'. For the moment let's use the
87 * non-timeout variant. :-/
88 */
89 #define interruptible_sleep_on_timeout(w,t) \
90 interruptible_sleep_on(w)
91
92 /*
93 * The macro implementation relies on current_set symbol, which doesn't
94 * appear to be available on GNU Mach. TODO: How to fix this properly?
95 */
96 #undef signal_pending
97 #define signal_pending(c) \
98 0
99
100
101 /*
102 * Byte order stuff. TODO: This does not work on big endian systems,
103 * does it? Move to asm-i386?
104 */
105 #include <asm/byteorder.h>
106 #ifndef le16_to_cpu
107 #define le16_to_cpu(x) (x)
108 #define le32_to_cpu(x) (x)
109 #endif
110 #ifndef cpu_to_le16
111 #define cpu_to_le16(val) (val)
112 #define cpu_to_le32(val) (val)
113 #endif
114
115
116 /*
117 * There is no `wake_up_interruptible' on GNU Mach. Use plain `wake_up'
118 * for the moment. TODO.
119 */
120 #define wake_up_interruptible wake_up
121
122
123 /* Eliminate the 4-arg versions from <linux/compatmac.h>. */
124 #undef pci_read_config_word
125 #undef pci_read_config_dword
126
127 #define bus_number(pci_dev) ((pci_dev)->bus->number)
128 #define devfn_number(pci_dev) ((pci_dev)->devfn)
129
130 #define pci_read_config_byte(pdev, where, valp) \
131 pcibios_read_config_byte(bus_number(pdev), devfn_number(pdev), where, valp)
132 #define pci_read_config_word(pdev, where, valp) \
133 pcibios_read_config_word(bus_number(pdev), devfn_number(pdev), where, valp)
134 #define pci_read_config_dword(pdev, where, valp) \
135 pcibios_read_config_dword(bus_number(pdev), devfn_number(pdev), where, valp)
136 #define pci_write_config_byte(pdev, where, val) \
137 pcibios_write_config_byte(bus_number(pdev), devfn_number(pdev), where, val)
138 #define pci_write_config_word(pdev, where, val) \
139 pcibios_write_config_word(bus_number(pdev), devfn_number(pdev), where, val)
140 #define pci_write_config_dword(pdev, where, val) \
141 pcibios_write_config_dword(bus_number(pdev), devfn_number(pdev), where, val)
142
143
144 /*
145 * From pcmcia-cs/include/linux/pci.h.
146 */
147 #define pci_for_each_dev(p) for (p = pci_devices; p; p = p->next)
148
149
150
151 /*
152 * These are defined in pci_fixup.c.
153 */
154 extern struct pci_dev *pci_find_slot(u_int bus, u_int devfn);
155 extern struct pci_dev *pci_find_class(u_int class, struct pci_dev *from);
156 extern int pci_set_power_state(struct pci_dev *dev, int state);
157 extern int pci_enable_device(struct pci_dev *dev);
158
159 extern u32 pci_irq_mask;
160
161
162 #ifdef PCMCIA_CLIENT
163 /*
164 * Worse enough, we need to have `mach_device' as well (at least in ds.c)
165 * and this one is typedef'd to `device', therefore we cannot just
166 * include `netdevice.h' when we're compiling the core.
167 *
168 * For compilation of the clients `PCMCIA_CLIENT' is defined through the
169 * Makefile.
170 */
171 #include <linux/netdevice.h>
172 #include <linux/kcomp.h>
173
174
175 /*
176 * init_dev_name and copy_dev_name glue (for `PCMCIA_CLIENT's only).
177 */
178 static inline void
179 init_dev_name(struct net_device *dev, dev_node_t node)
180 {
181 /* just allocate some space for the device name,
182 * register_netdev will happily provide one to us
183 */
184 dev->name = kmalloc(8, GFP_KERNEL);
185 dev->name[0] = 0;
186
187 /*
188 * dev->init needs to be initialized in order for register_netdev to work
189 */
190 int stub(struct device *dev)
191 {
192 (void) dev;
193 return 0;
194 }
195 dev->init = stub;
196 }
197
198 #define copy_dev_name(node, dev) do { } while (0)
199 #endif /* PCMCIA_CLIENT */
200
201
202 /*
203 * Some network interface glue, additional to the one from
204 * <linux/kcomp.h>.
205 */
206 #define netif_mark_up(dev) do { (dev)->start = 1; } while (0)
207 #define netif_mark_down(dev) do { (dev)->start = 0; } while (0)
208 #define netif_carrier_on(dev) do { dev->flags |= IFF_RUNNING; } while (0)
209 #define netif_carrier_off(dev) do { dev->flags &= ~IFF_RUNNING; } while (0)
210 #define tx_timeout_check(dev, tx_timeout) \
211 do { if (test_and_set_bit(0, (void *)&(dev)->tbusy) != 0) { \
212 if (jiffies - (dev)->trans_start < TX_TIMEOUT) return 1; \
213 tx_timeout(dev); \
214 } } while (0)
215
216
217 /*
218 * Some `struct netdevice' interface glue (from the pcmcia-cs package).
219 */
220 #define skb_tx_check(dev, skb) \
221 do { if (skb == NULL) { dev_tint(dev); return 0; } \
222 if (skb->len <= 0) return 0; } while (0)
223 #define tx_timeout_check(dev, tx_timeout) \
224 do { if (test_and_set_bit(0, (void *)&(dev)->tbusy) != 0) { \
225 if (jiffies - (dev)->trans_start < TX_TIMEOUT) return 1; \
226 tx_timeout(dev); \
227 } } while (0)
228 #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb, FREE_WRITE)
229 #define net_device_stats enet_statistics
230 #define add_rx_bytes(stats, n) do { int x; x = (n); } while (0)
231 #define add_tx_bytes(stats, n) do { int x; x = (n); } while (0)
232
233
234
235 /*
236 * TODO: This is i386 dependent.
237 */
238 #define readw_ns(p) readw(p)
239 #define writew_ns(v,p) writew(v,p)
240
241
242
243
244 /*
245 * We compile everything directly into the GNU Mach kernel, there are no
246 * modules.
247 */
248 #define MODULE_PARM(a,b)
249 #define MODULE_AUTHOR(a)
250 #define MODULE_DESCRIPTION(a)
251 #define MODULE_LICENSE(a)
252
253 #define module_init(a) \
254 void pcmcia_mod ## a (void) { a(); return; }
255 #define module_exit(a)
256
257 /*
258 * TODO: We don't have `disable_irq_nosync', do we need it? This is used
259 * by the axnet_cs client driver only.
260 */
261 #define disable_irq_nosync(irq) disable_irq(irq)
262
263
264 #endif /* _PCMCIA_GLUE_H */