Some minor additions to support newer versions of uhci driver (though doesn't even...
[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 0
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 bus_register(a) do {} while(0)
447 #define bus_unregister(a) do {} while(0)
448
449 /* DMA */
450 //#define dma_pool_alloc(a,b,c) my_dma_pool_alloc((a),(b),(c))
451 #define dma_pool_alloc(a,b,c) pci_pool_alloc(a,b,c)
452 #define dma_pool_create(a,b,c,d,e) pci_pool_create(a,b,c,d,e)
453 #define dma_pool_free(a,b,c) pci_pool_free(a,b,c)
454 #define dma_pool_destroy(a) pci_pool_destroy(a)
455
456 #define dma_alloc_coherent(a,b,c,d) NULL
457 #define dma_free_coherent(a,b,c,d) do {} while(0)
458
459 #define dma_map_single(a,b,c,d) ((u32)(b)&0xfffffff)
460 #define dma_unmap_single(a,b,c,d) do {} while(0)
461 #define pci_unmap_single(a,b,c,d) do {} while(0)
462 #define dma_sync_single(a,b,c,d) do {} while(0)
463 #define dma_sync_sg(a,b,c,d) do {} while(0)
464 #define dma_map_sg(a,b,c,d) 0
465 #define dma_unmap_sg(a,b,c,d) do {} while(0)
466
467 #define usb_create_driverfs_dev_files(a) do {} while(0)
468 #define usb_create_driverfs_intf_files(a) do {} while(0)
469 #define sg_dma_address(x) ((u32)((x)->page*4096 + (x)->offset))
470 #define sg_dma_len(x) ((x)->length)
471
472 #define page_address(x) ((void*)(x/4096))
473
474 #define DMA_TO_DEVICE 0
475 #define DMA_FROM_DEVICE 0
476 #define PCI_DMA_TODEVICE
477 #define PCI_DMA_FROMDEVICE
478 #define PCI_DMA_TODEVICE
479
480 #define PCI_ROM_RESOURCE 0
481 #define IORESOURCE_IO 1
482
483 #define DECLARE_WAITQUEUE(a,b) KEVENT a=0
484 #define init_waitqueue_head(a) my_init_waitqueue_head(a)
485 #define add_wait_queue(a,b) do {} while(0)
486 #define remove_wait_queue(a,b) do {} while(0)
487 void my_init_waitqueue_head(PKEVENT a);
488
489 VOID KeMemoryBarrier(VOID);
490
491 #define mb() KeMemoryBarrier()
492 #define wmb() __asm__ __volatile__ ("": : :"memory")
493 #define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
494
495 #define in_interrupt() 0
496
497 #define init_completion(x) (x)->done=0
498 #define wait_for_completion(x) my_wait_for_completion(x)
499 void my_wait_for_completion(struct completion*);
500
501 #define IRQ_NONE 0
502 #define IRQ_HANDLED 1
503
504 #define INIT_WORK(a,b,c) (a)->func=b
505
506 #define set_current_state(a) do {} while(0)
507
508 #define might_sleep() do {} while(0)
509 #define daemonize(a) do {} while(0)
510 #define allow_signal(a) do {} while(0)
511 #define wait_event_interruptible(x,y) do {} while(0)
512
513 #define interruptible_sleep_on(a) my_interruptible_sleep_on(a)
514 void my_interruptible_sleep_on(PKEVENT evnt);
515
516 #define flush_scheduled_work() do {} while(0)
517 #define refrigerator(x) do {} while(0)
518 #define signal_pending(x) 1 // fall through threads
519 #define complete_and_exit(a,b) return 0
520
521 //#define kill_proc(a,b,c) 0
522 #define kill_proc(a,b,c) my_kill_proc(a, b, c);
523 int my_kill_proc(int pid, int signal, int unk);
524
525 #define yield() do {} while(0)
526 #define cpu_relax() do {} while(0)
527
528 #define WARN_ON(a) do {} while(0)
529
530 /*------------------------------------------------------------------------*/
531 /* Lookaside lists funcs */
532 /*------------------------------------------------------------------------*/
533 #define kmem_cache_create(a,b,c,d,e,f) my_kmem_cache_create((a),(b),(c),(d),(e),(f))
534 #define kmem_cache_destroy(a) my_kmem_cache_destroy((a))
535 #define kmem_cache_alloc(co, flags) my_kmem_cache_alloc((co), (flags))
536 #define kmem_cache_free(co, ptr) my_kmem_cache_free((co), (ptr))
537
538 kmem_cache_t *my_kmem_cache_create(const char *tag, size_t alloc_size,
539 size_t offset, unsigned long flags,
540 void *ctor,
541 void *dtor);
542
543 BOOLEAN my_kmem_cache_destroy(kmem_cache_t *co);
544 void *my_kmem_cache_alloc(kmem_cache_t *co, int flags);
545 void my_kmem_cache_free(kmem_cache_t *co, void *ptr);
546
547 /*------------------------------------------------------------------------*/
548 /* Kernel macros */
549 /*------------------------------------------------------------------------*/
550
551 #define LINUX_VERSION_CODE 0x020572
552 #define UTS_SYSNAME "XBOX"
553 #define UTS_RELEASE "----"
554
555 /* from linux/kernel.h */
556 #define max_t(type,x,y) \
557 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
558
559 #define min_t(type,x,y) \
560 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
561
562 #define container_of(ptr, type, member) ({ \
563 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
564 (type *)( (char *)__mptr - offsetof(type,member) );})
565
566 /* from linux/stddef.h */
567
568 #undef offsetof
569 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
570
571 /*------------------------------------------------------------------------*/
572 /* Conversion macros */
573 /*------------------------------------------------------------------------*/
574
575 #define __constant_cpu_to_le32(x) (x)
576 #define cpu_to_le16(x) (x)
577 #define le16_to_cpu(x) (x)
578 #define cpu_to_le32(x) (x)
579 #define cpu_to_le32p(x) (*(__u32*)(x))
580 #define le32_to_cpup(x) (*(__u32*)(x))
581 #define le32_to_cpu(x) ((u32)x)
582 #define le16_to_cpus(x) do {} while (0)
583 #define le16_to_cpup(x) (*(__u16*)(x))
584 #define cpu_to_le16p(x) (*(__u16*)(x))
585
586 /*------------------------------------------------------------------------*/
587 /* Debug output */
588 /*------------------------------------------------------------------------*/
589 #ifdef DEBUG_MODE
590 #define dev_printk(lvl,x,f,arg...) printk(f, ## arg)
591 #define dev_dbg(x,f,arg...) printk(f, ## arg)
592 #define dev_info(x,f,arg...) printk(f,## arg)
593 #define dev_warn(x,f,arg...) printk(f,## arg)
594 #define dev_err(x,f,arg...) printk(f,## arg)
595 #define pr_debug(x,f,arg...) printk(f,## arg)
596 #define usbprintk printk
597 #endif
598
599 #ifndef DEBUG_MODE
600 #define dev_printk(lvl,x,f,arg...) do {} while (0)
601 #define dev_dbg(x,f,arg...) do {} while (0) //printk(f, ## arg)
602 #define dev_info(x,f,arg...) do {} while (0)
603 #define dev_warn(x,f,arg...) do {} while (0)
604 #define dev_err(x,f,arg...) do {} while (0)
605 #define pr_debug(x,f,arg...) do {} while (0)
606 #define usbprintk
607 #endif
608
609
610
611 #define PCI_DEVFN(a,b) 0
612 #define PCI_SLOT(a) 0
613
614 /**
615 * PCI_DEVICE_CLASS - macro used to describe a specific pci device class
616 * @dev_class: the class, subclass, prog-if triple for this device
617 * @dev_class_mask: the class mask for this device
618 *
619 * This macro is used to create a struct pci_device_id that matches a
620 * specific PCI class. The vendor, device, subvendor, and subdevice
621 * fields will be set to PCI_ANY_ID.
622 */
623 #define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
624 .class = (dev_class), .class_mask = (dev_class_mask), \
625 .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
626 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
627
628
629 /*------------------------------------------------------------------------*/
630 /* Stuff from kernel */
631 /*------------------------------------------------------------------------*/
632
633 #include "errno.h"
634 #include "bitops.h"
635 //#include "linux/pci_ids.h"
636
637 /*------------------------------------------------------------------------*/
638 /* global variables */
639 /*------------------------------------------------------------------------*/
640
641 #define jiffies my_jiffies
642 extern int my_jiffies;
643 #define current my_current
644 extern struct dummy_process *my_current;
645
646 extern struct list_head interrupt_list;
647
648 /*------------------------------------------------------------------------*/
649 /* Function prototypes */
650 /*------------------------------------------------------------------------*/
651 void STDCALL usb_hcd_pci_remove (struct pci_dev *dev);
652
653 #define my_wait_ms(x) wait_ms(x)
654
655 #define my_udelay(x) wait_ms(x)
656 #define udelay(x) my_udelay(x)
657
658 #define my_mdelay(x) wait_ms(1+x/1000);
659 #define mdelay(x) my_mdelay(x);
660
661 #define pci_find_slot(a,b) my_pci_find_slot(a,b)
662 struct pci_dev *my_pci_find_slot(int a,int b);
663
664 /*------------------------------------------------------------------------*/
665 /* Timer management */
666 /*------------------------------------------------------------------------*/
667
668 #define MAX_TIMERS 20
669 extern struct timer_list *main_timer_list[MAX_TIMERS];
670
671 static void __inline__ init_timer(struct timer_list* t)
672 {
673 INIT_LIST_HEAD(&t->timer_list);
674 t->function=NULL;
675 t->expires=0;
676 }
677
678 static void __inline__ add_timer(struct timer_list* t)
679 {
680 int n;
681 for(n=0;n<MAX_TIMERS;n++)
682 if (main_timer_list[n]==0)
683 {
684 main_timer_list[n]=t;
685 break;
686 }
687 }
688
689 static void __inline__ del_timer(struct timer_list* t)
690 {
691 int n;
692 for(n=0;n<MAX_TIMERS;n++)
693 if (main_timer_list[n]==t)
694 {
695 main_timer_list[n]=0;
696 break;
697 }
698 }
699 static void __inline__ del_timer_sync(struct timer_list* t)
700 {
701 int n;
702 for(n=0;n<MAX_TIMERS;n++)
703 if (main_timer_list[n]==t)
704 {
705 main_timer_list[n]=0;
706 break;
707 }
708
709 }
710 static void __inline__ mod_timer(struct timer_list* t, int ex)
711 {
712 del_timer(t);
713 t->expires=ex;
714 add_timer(t);
715 }
716
717 #define time_after_eq(a,b) \
718 (((long)(a) - (long)(b) >= 0))
719
720 /*------------------------------------------------------------------------*/
721 /* Device driver and process related stuff */
722 /*------------------------------------------------------------------------*/
723
724 static int __inline__ usb_major_init(void){return 0;}
725 static void __inline__ usb_major_cleanup(void){}
726 static void __inline__ schedule_work(void* p){}
727
728 #define device_initialize(x) my_device_initialize(x)
729 void my_device_initialize(struct device *dev);
730
731 #define get_device(x) my_get_device(x)
732 struct device *my_get_device(struct device *dev);
733
734 #define device_add(x) my_device_add(x)
735 int my_device_add(struct device *dev);
736
737 #define driver_register(x) my_driver_register(x)
738 int my_driver_register(struct device_driver *driver);
739
740 #define device_unregister(a) my_device_unregister(a)
741 int my_device_unregister(struct device *dev);
742
743 #define DEVICE_ATTR(a,b,c,d) int xxx_##a
744 #define device_create_file(a,b) do {} while(0)
745 #define device_remove_file(a,b) do {} while(0)
746
747 #define schedule_timeout(x) my_schedule_timeout(x)
748 int my_schedule_timeout(int x);
749
750 #define wake_up(x) my_wake_up(x)
751 void my_wake_up(PKEVENT);
752
753 // cannot be mapped via macro due to collision with urb->complete
754 static void __inline__ complete(struct completion *p)
755 {
756 /* Wake up x->wait */
757 p->done++;
758 wake_up(&p->wait);
759 }
760
761 #define kernel_thread(a,b,c) my_kernel_thread(a,b,c)
762 int my_kernel_thread(int STDCALL (*handler)(void*), void* parm, int flags);
763
764 /*------------------------------------------------------------------------*/
765 /* PCI, simple and inlined... */
766 /*------------------------------------------------------------------------*/
767 #include "pci_hal.c"
768
769 /*------------------------------------------------------------------------*/
770 /* IRQ handling */
771 /*------------------------------------------------------------------------*/
772
773 #define request_irq(a,b,c,d,e) my_request_irq(a,b,c,d,e)
774 int my_request_irq(unsigned int irq,
775 int (*handler)(int, void *, struct pt_regs *),
776 unsigned long mode, const char *desc, void *data);
777
778 #define free_irq(a,b) my_free_irq(a,b)
779 int free_irq(int irq, void* p);
780
781
782
783 struct my_irqs {
784 int (*handler)(int, void *, struct pt_regs *);
785 int irq;
786 void* data;
787 };
788
789 #define MAX_IRQS 8
790
791 // Exported to top level
792
793 void handle_irqs(int irq);
794 void inc_jiffies(int);
795 void init_wrapper(struct pci_dev *pci_dev);
796 void do_all_timers(void);
797
798 #define __KERNEL_DS 0x18
799
800