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