SVN maintenance:
[reactos.git] / reactos / drivers / usb / cromwell / linux / linux_wrapper.h
1 /*
2 * linux-wrapper.h
3 *
4 * Hard coded Linux kernel replacements for x86
5 *
6 * (c) 2003 Georg Acher (georg@acher.org)
7 *
8 * Emulation of:
9 * typedefs
10 * structs
11 * macros
12 *
13 * All structs and prototypes are based on kernel source 2.5.72
14 *
15 * Modified by Aleksey Bragin (aleksey@reactos.com) for ReactOS needs
16 *
17 *
18 * #include <standard-GPL-header.h>
19 */
20
21 /*------------------------------------------------------------------------*/
22 /* Typedefs */
23 /*------------------------------------------------------------------------*/
24 #include "cromwell_types.h"
25
26 typedef unsigned int __u32;
27 //typedef __u32 u32;
28 typedef unsigned short __u16;
29 //typedef __u16 u16;
30 typedef unsigned char __u8;
31 //typedef __u8 u8;
32
33 typedef short s16;
34
35 typedef u32 dma_addr_t;
36
37 typedef int spinlock_t;
38 typedef int atomic_t;
39 #ifndef STANDALONE
40 typedef int mode_t;
41 typedef int pid_t;
42 typedef int ssize_t;
43
44 #endif
45 typedef int irqreturn_t;
46 typedef unsigned long kernel_ulong_t;
47
48 typedef int wait_queue_head_t;
49 /*------------------------------------------------------------------------*/
50 /* Stuff from xbox/linux environment */
51 /*------------------------------------------------------------------------*/
52
53 #include "list.h"
54
55 #ifndef STANDALONE
56 #ifdef MODULE
57 typedef int size_t;
58 #define NULL ((void*)0)
59 extern void * memset(void *,int,unsigned int);
60 extern void * memcpy(void *,const void *,unsigned int);
61 #if 0
62 extern char * strcpy(char *,const char *);
63 #else
64 static inline char * strcpy(char * dest,const char *src)
65 {
66 int d0, d1, d2;
67 __asm__ __volatile__(
68 "1:\tlodsb\n\t"
69 "stosb\n\t"
70 "testb %%al,%%al\n\t"
71 "jne 1b"
72 : "=&S" (d0), "=&D" (d1), "=&a" (d2)
73 :"0" (src),"1" (dest) : "memory");
74 return dest;
75 }
76 #endif
77 extern size_t strlen(const char *);
78
79 extern int memcmp(const void *,const void *,unsigned int);
80
81 #else
82 #include "boot.h"
83 #include "config.h"
84 #endif
85 #else
86 #include <stdarg.h>
87 #include <stdio.h>
88 #include <stdlib.h>
89 #include "consts.h"
90 #include <string.h>
91 #endif
92
93 /*------------------------------------------------------------------------*/
94 /* General structs */
95 /*------------------------------------------------------------------------*/
96
97 struct timer_list {
98 void (*function)(unsigned long);
99 unsigned long data;
100 int expires;
101 struct list_head timer_list;
102 };
103
104 struct work_struct {
105 void (*func)(void *);
106 };
107 struct device {
108 char name[128];
109 struct bus_type *bus;
110 int dma_mask;
111 char bus_id[16];
112 struct device_driver* driver;
113 void *driver_data;
114 struct device *parent;
115 struct list_head driver_list;
116 void (*release)(struct device * dev);
117 };
118 struct class_device{int a;};
119 struct semaphore{int a;};
120
121 struct device_driver{
122 char *name;
123 struct bus_type *bus;
124 int (*probe) (struct device * dev);
125 int (*remove) (struct device * dev);
126 struct list_head devices;
127 };
128
129 struct bus_type {
130 char * name;
131 int (*match)(struct device * dev, struct device_driver * drv);
132 struct device * (*add) (struct device * parent, char * bus_id);
133 int (*hotplug) (struct device *dev, char **envp,
134 int num_envp, char *buffer, int buffer_size);
135 };
136
137 struct dummy_process
138 {
139 int flags;
140 };
141
142 struct pt_regs
143 {
144 int a;
145 };
146 struct completion {
147 unsigned int done;
148 wait_queue_head_t wait;
149 };
150
151 // windows lookaside list head
152 typedef void* kmem_cache_t;
153
154 struct dma_pool
155 {
156 int dummy;
157 };
158
159 /* from mod_devicetable.h */
160
161 struct usb_device_id {
162 /* which fields to match against? */
163 __u16 match_flags;
164
165 /* Used for product specific matches; range is inclusive */
166 __u16 idVendor;
167 __u16 idProduct;
168 __u16 bcdDevice_lo;
169 __u16 bcdDevice_hi;
170
171 /* Used for device class matches */
172 __u8 bDeviceClass;
173 __u8 bDeviceSubClass;
174 __u8 bDeviceProtocol;
175
176 /* Used for interface class matches */
177 __u8 bInterfaceClass;
178 __u8 bInterfaceSubClass;
179 __u8 bInterfaceProtocol;
180
181 /* not matched against */
182 kernel_ulong_t driver_info;
183 };
184
185 /* Some useful macros to use to create struct usb_device_id */
186 #define USB_DEVICE_ID_MATCH_VENDOR 0x0001
187 #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
188 #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
189 #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
190 #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
191 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
192 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
193 #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
194 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
195 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
196
197 /*------------------------------------------------------------------------*/
198 /* imported functions from top-level */
199 /*------------------------------------------------------------------------*/
200
201 //void zxprintf(char* fmt, ...);
202 //void zxsprintf(char *buffer, char* fmt, ...);
203 //int zxsnprintf(char *buffer, size_t s, char* fmt, ...);
204
205 /*------------------------------------------------------------------------*/
206 /* PCI structs (taken from linux/pci.h et al., but slightly modified) */
207 /*------------------------------------------------------------------------*/
208
209 struct pci_dev {
210 int vendor;
211 int device;
212 struct pci_bus *bus;
213 int irq;
214 char *slot_name;
215 struct device dev;
216 int base[4];
217 int flags[4];
218 void * data;
219 void * dev_ext; // link to Windows DeviceExtension
220 };
221
222 struct pci_bus {
223 unsigned char number;
224 };
225
226 struct pci_device_id {
227 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
228 __u32 subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
229 __u32 class, class_mask; /* (class,subclass,prog-if) triplet */
230 kernel_ulong_t driver_data; /* Data private to the driver */
231 };
232
233 struct pci_driver {
234 struct list_head node;
235 char *name;
236 const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
237 int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
238 void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
239 int (*save_state) (struct pci_dev *dev, u32 state); /* Save Device Context */
240 int (*suspend) (struct pci_dev *dev, u32 state); /* Device suspended */
241 int (*resume) (struct pci_dev *dev); /* Device woken up */
242 int (*enable_wake) (struct pci_dev *dev, u32 state, int enable); /* Enable wake event */
243 };
244
245 struct scatterlist
246 {
247 int page;
248 int offset;
249 int length;
250 };
251
252 struct usbdevfs_hub_portinfo
253 {
254 int nports;
255 int port[8];
256 };
257
258 /*------------------------------------------------------------------------*/
259 /* constant defines */
260 /*------------------------------------------------------------------------*/
261
262 #define TASK_UNINTERRUPTIBLE 0
263 #define HZ 100 /* Don't rely on that... */
264 #define KERN_DEBUG "DBG: "
265 #define KERN_ERR "ERR: "
266 #define KERN_WARNING "WRN: "
267 #define KERN_INFO "INF: "
268 #define GFP_KERNEL 0
269 #define GFP_ATOMIC 0x20
270 #define GFP_NOIO 0
271 #define SLAB_ATOMIC 0
272 #define PCI_ANY_ID (~0)
273 #define SIGKILL 9
274 #define THIS_MODULE 0
275 //#define PAGE_SIZE 4096
276
277
278 #define CLONE_FS 0
279 #define CLONE_FILES 0
280 #define CLONE_SIGHAND 0
281 #define PF_FREEZE 0
282 #define PF_IOTHREAD 0
283
284
285 #define USBDEVFS_HUB_PORTINFO 1234
286 #define SA_SHIRQ 0
287
288 #undef PCI_COMMAND
289 #define PCI_COMMAND 0
290 #undef PCI_COMMAND_MASTER
291 #define PCI_COMMAND_MASTER 0
292 /*------------------------------------------------------------------------*/
293 /* Module/export macros */
294 /*------------------------------------------------------------------------*/
295
296 #define MODULE_AUTHOR(a)
297 #define MODULE_DESCRIPTION(a)
298 #define MODULE_LICENSE(a)
299 #define MODULE_DEVICE_TABLE(type,name) void* module_table_##name=&name
300 #define MODULE_PARM(a,b)
301 #define MODULE_PARM_DESC(a,b)
302
303 #define __devinit
304 #define __exit
305 #define __init
306 #define __devinitdata
307 #define module_init(x) static void module_init_##x(void){ x();}
308 #define module_exit(x) void module_exit_##x(void){ x();}
309 #define EXPORT_SYMBOL_GPL(x)
310 #define EXPORT_SYMBOL(x)
311
312 #define __setup(x,y) int setup_##y=(int)y
313 #define subsys_initcall(x) void subsys_##x(void){x();}
314
315 /*------------------------------------------------------------------------*/
316 /* Access macros */
317 /*------------------------------------------------------------------------*/
318
319 #define dev_get_drvdata(a) (a)->driver_data
320 #define dev_set_drvdata(a,b) (a)->driver_data=(b)
321
322 #define __io_virt(x) ((void *)(x))
323 #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
324 #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
325 #define likely(x) (x)
326 #define unlikely(x) (x)
327 #define prefetch(x) 1
328
329 #define inw(x) READ_PORT_USHORT((PUSHORT)(x))
330 #define outw(x,p) WRITE_PORT_USHORT((PUSHORT)(p),(x))
331 #define outl(x,p) WRITE_PORT_ULONG((PUSHORT)(p),(x))
332
333 /* The kernel macro for list_for_each_entry makes nonsense (have no clue
334 * why, this is just the same definition...) */
335
336 #undef list_for_each_entry
337 #define list_for_each_entry(pos, head, member) \
338 for (pos = list_entry((head)->next, typeof(*pos), member), \
339 prefetch(pos->member.next); \
340 &pos->member != (head); \
341 pos = list_entry(pos->member.next, typeof(*pos), member), \
342 prefetch(pos->member.next))
343
344 /*------------------------------------------------------------------------*/
345 /* function wrapper macros */
346 /*------------------------------------------------------------------------*/
347 #define kmalloc(x,y) ExAllocatePool(PagedPool,x)
348 #define kfree(x) ExFreePool(x)
349
350 //#define sprintf(a,b,format, arg...) zxsprintf((a),(b),format, ## arg)
351 //#define snprintf(a,b,format, arg...) zxsnprintf((a),(b),format, ##arg)
352 //#define printk(format, arg...) zxprintf(format, ## arg)
353 #define snprintf(a,b,format, arg...) _snprintf((a),(b),format, ##arg)
354 #define printk(format, arg...) DPRINT1(format, ## arg)
355 #define BUG(...) do {} while(0)
356
357 /* Locks & friends */
358
359 #define DECLARE_MUTEX(x) struct semaphore x
360 #define init_MUTEX(x)
361
362 #define SPIN_LOCK_UNLOCKED 0
363 #define spin_lock_init(a) do {} while(0)
364 #define spin_lock(a) *(int*)a=1
365 #define spin_unlock(a) do {} while(0)
366
367 #define spin_lock_irqsave(a,b) b=0
368 #define spin_unlock_irqrestore(a,b)
369
370 #if 0
371 #define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
372 #define local_irq_restore(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
373 #else
374 #define local_irq_save(x) do {} while(0)
375 #define local_irq_restore(x) do {} while(0)
376 #endif
377
378 #define atomic_inc(x) *(x)+=1
379 #define atomic_dec(x) *(x)-=1
380 #define atomic_dec_and_test(x) (*(x)-=1,(*(x))==0)
381 #define atomic_set(x,a) *(x)=a
382 #define atomic_read(x) *(x)
383 #define ATOMIC_INIT(x) (x)
384
385 #define down(x) do {} while(0)
386 #define up(x) do {} while(0)
387 #define down_trylock(a) 0
388
389 #define down_read(a) do {} while(0)
390 #define up_read(a) do {} while(0)
391
392 #define DECLARE_WAIT_QUEUE_HEAD(x) KEVENT x
393
394 #define DECLARE_COMPLETION(x) struct completion x
395
396 /* driver */
397
398 #define driver_unregister(a) do {} while(0)
399 #define put_device(a) do {} while(0)
400
401
402 /* PCI */
403 #define to_pci_dev(n) container_of(n, struct pci_dev, dev)
404
405 #define pci_pool_create(a,b,c,d,e) (void*)1
406
407 #define pci_pool_alloc(a,b,c) my_pci_pool_alloc(a,b,c)
408
409 static void __inline__ *my_pci_pool_alloc(void* pool, size_t size,
410 dma_addr_t *dma_handle)
411 {
412 void* a;
413 a=kmalloc(size,0); //FIXME
414 #ifdef MODULE
415 *dma_handle=((u32)a)&0xfffffff;
416 #else
417 *dma_handle=(u32)a;
418 #endif
419 return a;
420 }
421
422
423 #define pci_pool_free(a,b,c) kfree(b)
424 #define pci_alloc_consistent(a,b,c) my_pci_alloc_consistent(a,b,c)
425
426 static void __inline__ *my_pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
427 dma_addr_t *dma_handle)
428 {
429 void* a;
430
431 a=kmalloc(size+256,0); //FIXME
432 a=(void*)(((int)a+255)&~255); // 256 alignment
433 *dma_handle=((u32)a)&0xfffffff;
434
435 return a;
436 }
437
438 #define pci_free_consistent(a,b,c,d) kfree(c)
439 #define pci_pool_destroy(a) do {} while(0)
440
441 #define pci_module_init(x) my_pci_module_init(x)
442 int my_pci_module_init(struct pci_driver *x);
443
444 #define pci_unregister_driver(a) do {} while(0)
445
446 #define pci_write_config_word(a,b,c) my_pci_write_config_word(a,b,c)
447
448 #define bus_register(a) do {} while(0)
449 #define bus_unregister(a) do {} while(0)
450
451 /* DMA */
452 //#define dma_pool_alloc(a,b,c) my_dma_pool_alloc((a),(b),(c))
453 #define dma_pool_alloc(a,b,c) pci_pool_alloc(a,b,c)
454 #define dma_pool_create(a,b,c,d,e) pci_pool_create(a,b,c,d,e)
455 #define dma_pool_free(a,b,c) pci_pool_free(a,b,c)
456 #define dma_pool_destroy(a) pci_pool_destroy(a)
457
458 #define dma_alloc_coherent(a,b,c,d) NULL
459 #define dma_free_coherent(a,b,c,d) do {} while(0)
460
461 #define dma_map_single(a,b,c,d) ((u32)(b)&0xfffffff)
462 #define dma_unmap_single(a,b,c,d) do {} while(0)
463 #define pci_unmap_single(a,b,c,d) do {} while(0)
464 #define dma_sync_single(a,b,c,d) do {} while(0)
465 #define dma_sync_sg(a,b,c,d) do {} while(0)
466 #define dma_map_sg(a,b,c,d) 0
467 #define dma_unmap_sg(a,b,c,d) do {} while(0)
468
469 #define usb_create_driverfs_dev_files(a) do {} while(0)
470 #define usb_create_driverfs_intf_files(a) do {} while(0)
471 #define sg_dma_address(x) ((u32)((x)->page*4096 + (x)->offset))
472 #define sg_dma_len(x) ((x)->length)
473
474 #define page_address(x) ((void*)(x/4096))
475
476 #define DMA_TO_DEVICE 0
477 #define DMA_FROM_DEVICE 0
478 #define PCI_DMA_TODEVICE
479 #define PCI_DMA_FROMDEVICE
480 #define PCI_DMA_TODEVICE
481
482 #define PCI_ROM_RESOURCE 1
483 #define IORESOURCE_IO CM_RESOURCE_PORT_IO
484
485 #define DECLARE_WAITQUEUE(a,b) KEVENT a=0
486 #define init_waitqueue_head(a) my_init_waitqueue_head(a)
487 #define add_wait_queue(a,b) do {} while(0)
488 #define remove_wait_queue(a,b) do {} while(0)
489 void my_init_waitqueue_head(PKEVENT a);
490
491 VOID KeMemoryBarrier(VOID);
492
493 #define mb() KeMemoryBarrier()
494 #define wmb() __asm__ __volatile__ ("": : :"memory")
495 #define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
496
497 #define in_interrupt() 0
498
499 #define init_completion(x) (x)->done=0
500 #define wait_for_completion(x) my_wait_for_completion(x)
501 void my_wait_for_completion(struct completion*);
502
503 #define IRQ_NONE 0
504 #define IRQ_HANDLED 1
505
506 #define INIT_WORK(a,b,c) (a)->func=b
507
508 #define set_current_state(a) do {} while(0)
509
510 #define might_sleep() do {} while(0)
511 #define daemonize(a) do {} while(0)
512 #define allow_signal(a) do {} while(0)
513 #define wait_event_interruptible(x,y) do {} while(0)
514
515 #define interruptible_sleep_on(a) my_interruptible_sleep_on(a)
516 void my_interruptible_sleep_on(PKEVENT evnt);
517
518 #define flush_scheduled_work() do {} while(0)
519 #define refrigerator(x) do {} while(0)
520 #define signal_pending(x) 1 // fall through threads
521 #define complete_and_exit(a,b) return 0
522
523 //#define kill_proc(a,b,c) 0
524 #define kill_proc(a,b,c) my_kill_proc(a, b, c);
525 int my_kill_proc(int pid, int signal, int unk);
526
527 #define yield() do {} while(0)
528 #define cpu_relax() do {} while(0)
529
530 #define WARN_ON(a) do {} while(0)
531
532 /*------------------------------------------------------------------------*/
533 /* Lookaside lists funcs */
534 /*------------------------------------------------------------------------*/
535 #define kmem_cache_create(a,b,c,d,e,f) my_kmem_cache_create((a),(b),(c),(d),(e),(f))
536 #define kmem_cache_destroy(a) my_kmem_cache_destroy((a))
537 #define kmem_cache_alloc(co, flags) my_kmem_cache_alloc((co), (flags))
538 #define kmem_cache_free(co, ptr) my_kmem_cache_free((co), (ptr))
539
540 kmem_cache_t *my_kmem_cache_create(const char *tag, size_t alloc_size,
541 size_t offset, unsigned long flags,
542 void *ctor,
543 void *dtor);
544
545 BOOLEAN my_kmem_cache_destroy(kmem_cache_t *co);
546 void *my_kmem_cache_alloc(kmem_cache_t *co, int flags);
547 void my_kmem_cache_free(kmem_cache_t *co, void *ptr);
548
549 /*------------------------------------------------------------------------*/
550 /* Kernel macros */
551 /*------------------------------------------------------------------------*/
552
553 #define LINUX_VERSION_CODE 0x020572
554 #define UTS_SYSNAME "XBOX"
555 #define UTS_RELEASE "----"
556
557 /* from linux/kernel.h */
558 #define max_t(type,x,y) \
559 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
560
561 #define min_t(type,x,y) \
562 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
563
564 #define container_of(ptr, type, member) ({ \
565 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
566 (type *)( (char *)__mptr - offsetof(type,member) );})
567
568 /* from linux/stddef.h */
569
570 #undef offsetof
571 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
572
573 /*------------------------------------------------------------------------*/
574 /* Conversion macros */
575 /*------------------------------------------------------------------------*/
576
577 #define __constant_cpu_to_le32(x) (x)
578 #define cpu_to_le16(x) (x)
579 #define le16_to_cpu(x) (x)
580 #define cpu_to_le32(x) (x)
581 #define cpu_to_le32p(x) (*(__u32*)(x))
582 #define le32_to_cpup(x) (*(__u32*)(x))
583 #define le32_to_cpu(x) ((u32)x)
584 #define le16_to_cpus(x) do {} while (0)
585 #define le16_to_cpup(x) (*(__u16*)(x))
586 #define cpu_to_le16p(x) (*(__u16*)(x))
587
588 /*------------------------------------------------------------------------*/
589 /* Debug output */
590 /*------------------------------------------------------------------------*/
591 #ifdef DEBUG_MODE
592 #define dev_printk(lvl,x,f,arg...) printk(f, ## arg)
593 #define dev_dbg(x,f,arg...) printk(f, ## arg)
594 #define dev_info(x,f,arg...) printk(f,## arg)
595 #define dev_warn(x,f,arg...) printk(f,## arg)
596 #define dev_err(x,f,arg...) printk(f,## arg)
597 #define pr_debug(x,f,arg...) printk(f,## arg)
598 #define usbprintk printk
599 #endif
600
601 #ifndef DEBUG_MODE
602 #define dev_printk(lvl,x,f,arg...) do {} while (0)
603 #define dev_dbg(x,f,arg...) do {} while (0) //printk(f, ## arg)
604 #define dev_info(x,f,arg...) do {} while (0)
605 #define dev_warn(x,f,arg...) do {} while (0)
606 #define dev_err(x,f,arg...) do {} while (0)
607 #define pr_debug(x,f,arg...) do {} while (0)
608 #define usbprintk
609 #endif
610
611
612
613 #define PCI_DEVFN(a,b) 0
614 #define PCI_SLOT(a) 0
615
616 /**
617 * PCI_DEVICE_CLASS - macro used to describe a specific pci device class
618 * @dev_class: the class, subclass, prog-if triple for this device
619 * @dev_class_mask: the class mask for this device
620 *
621 * This macro is used to create a struct pci_device_id that matches a
622 * specific PCI class. The vendor, device, subvendor, and subdevice
623 * fields will be set to PCI_ANY_ID.
624 */
625 #define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
626 .class = (dev_class), .class_mask = (dev_class_mask), \
627 .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
628 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
629
630
631 /*------------------------------------------------------------------------*/
632 /* Stuff from kernel */
633 /*------------------------------------------------------------------------*/
634
635 #include "errno.h"
636 #include "bitops.h"
637 //#include "linux/pci_ids.h"
638
639 /*------------------------------------------------------------------------*/
640 /* global variables */
641 /*------------------------------------------------------------------------*/
642
643 #define jiffies my_jiffies
644 extern int my_jiffies;
645 #define current my_current
646 extern struct dummy_process *my_current;
647
648 extern struct list_head interrupt_list;
649
650 /*------------------------------------------------------------------------*/
651 /* Function prototypes */
652 /*------------------------------------------------------------------------*/
653 void STDCALL usb_hcd_pci_remove (struct pci_dev *dev);
654
655 #define my_wait_ms(x) wait_ms(x)
656
657 #define my_udelay(x) wait_ms(x)
658 #define udelay(x) my_udelay(x)
659
660 #define my_mdelay(x) wait_ms(1+x/1000);
661 #define mdelay(x) my_mdelay(x);
662
663 #define pci_find_slot(a,b) my_pci_find_slot(a,b)
664 struct pci_dev *my_pci_find_slot(int a,int b);
665
666 /*------------------------------------------------------------------------*/
667 /* Timer management */
668 /*------------------------------------------------------------------------*/
669
670 #define MAX_TIMERS 20
671 extern struct timer_list *main_timer_list[MAX_TIMERS];
672
673 static void __inline__ init_timer(struct timer_list* t)
674 {
675 INIT_LIST_HEAD(&t->timer_list);
676 t->function=NULL;
677 t->expires=0;
678 }
679
680 static void __inline__ add_timer(struct timer_list* t)
681 {
682 int n;
683 for(n=0;n<MAX_TIMERS;n++)
684 if (main_timer_list[n]==0)
685 {
686 main_timer_list[n]=t;
687 break;
688 }
689 }
690
691 static void __inline__ del_timer(struct timer_list* t)
692 {
693 int n;
694 for(n=0;n<MAX_TIMERS;n++)
695 if (main_timer_list[n]==t)
696 {
697 main_timer_list[n]=0;
698 break;
699 }
700 }
701 static void __inline__ del_timer_sync(struct timer_list* t)
702 {
703 int n;
704 for(n=0;n<MAX_TIMERS;n++)
705 if (main_timer_list[n]==t)
706 {
707 main_timer_list[n]=0;
708 break;
709 }
710
711 }
712 static void __inline__ mod_timer(struct timer_list* t, int ex)
713 {
714 del_timer(t);
715 t->expires=ex;
716 add_timer(t);
717 }
718
719 #define time_after_eq(a,b) \
720 (((long)(a) - (long)(b) >= 0))
721
722 /*------------------------------------------------------------------------*/
723 /* Device driver and process related stuff */
724 /*------------------------------------------------------------------------*/
725
726 static int __inline__ usb_major_init(void){return 0;}
727 static void __inline__ usb_major_cleanup(void){}
728 static void __inline__ schedule_work(void* p){}
729
730 #define device_initialize(x) my_device_initialize(x)
731 void my_device_initialize(struct device *dev);
732
733 #define get_device(x) my_get_device(x)
734 struct device *my_get_device(struct device *dev);
735
736 #define device_add(x) my_device_add(x)
737 int my_device_add(struct device *dev);
738
739 #define driver_register(x) my_driver_register(x)
740 int my_driver_register(struct device_driver *driver);
741
742 #define device_unregister(a) my_device_unregister(a)
743 int my_device_unregister(struct device *dev);
744
745 #define DEVICE_ATTR(a,b,c,d) int xxx_##a
746 #define device_create_file(a,b) do {} while(0)
747 #define device_remove_file(a,b) do {} while(0)
748
749 #define schedule_timeout(x) my_schedule_timeout(x)
750 int my_schedule_timeout(int x);
751
752 #define wake_up(x) my_wake_up(x)
753 void my_wake_up(PKEVENT);
754
755 // cannot be mapped via macro due to collision with urb->complete
756 static void __inline__ complete(struct completion *p)
757 {
758 /* Wake up x->wait */
759 p->done++;
760 wake_up(&p->wait);
761 }
762
763 #define kernel_thread(a,b,c) my_kernel_thread(a,b,c)
764 int my_kernel_thread(int STDCALL (*handler)(void*), void* parm, int flags);
765
766 /*------------------------------------------------------------------------*/
767 /* PCI, simple and inlined... */
768 /*------------------------------------------------------------------------*/
769 #include "pci_hal.c"
770
771 /*------------------------------------------------------------------------*/
772 /* IRQ handling */
773 /*------------------------------------------------------------------------*/
774
775 #define request_irq(a,b,c,d,e) my_request_irq(a,b,c,d,e)
776 int my_request_irq(unsigned int irq,
777 int (*handler)(int, void *, struct pt_regs *),
778 unsigned long mode, const char *desc, void *data);
779
780 #define free_irq(a,b) my_free_irq(a,b)
781 int free_irq(int irq, void* p);
782
783
784
785 struct my_irqs {
786 int (*handler)(int, void *, struct pt_regs *);
787 int irq;
788 void* data;
789 };
790
791 #define MAX_IRQS 8
792
793 // Exported to top level
794
795 void handle_irqs(int irq);
796 void inc_jiffies(int);
797 void init_wrapper(struct pci_dev *pci_dev);
798 void do_all_timers(void);
799
800 #define __KERNEL_DS 0x18
801
802