4 * Hard coded Linux kernel replacements for x86
6 * (c) 2003 Georg Acher (georg@acher.org)
13 * All structs and prototypes are based on kernel source 2.5.72
15 * Modified by Aleksey Bragin (aleksey@reactos.com) for ReactOS needs
18 * #include <standard-GPL-header.h>
21 /*------------------------------------------------------------------------*/
23 /*------------------------------------------------------------------------*/
24 #include "cromwell_types.h"
26 typedef unsigned int __u32
;
28 typedef unsigned short __u16
;
30 typedef unsigned char __u8
;
35 typedef u32 dma_addr_t
;
37 typedef int spinlock_t
;
45 typedef int irqreturn_t
;
46 typedef unsigned long kernel_ulong_t
;
48 typedef int wait_queue_head_t
;
49 /*------------------------------------------------------------------------*/
50 /* Stuff from xbox/linux environment */
51 /*------------------------------------------------------------------------*/
58 #define NULL ((void*)0)
59 extern void * memset(void *,int,unsigned int);
60 extern void * memcpy(void *,const void *,unsigned int);
62 extern char * strcpy(char *,const char *);
64 static inline char * strcpy(char * dest
,const char *src
)
72 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
)
73 :"0" (src
),"1" (dest
) : "memory");
77 extern size_t strlen(const char *);
79 extern int memcmp(const void *,const void *,unsigned int);
93 /*------------------------------------------------------------------------*/
95 /*------------------------------------------------------------------------*/
98 void (*function
)(unsigned long);
101 struct list_head timer_list
;
105 void (*func
)(void *);
109 struct bus_type
*bus
;
112 struct device_driver
* driver
;
114 struct device
*parent
;
115 struct list_head driver_list
;
116 void (*release
)(struct device
* dev
);
118 struct class_device
{int a
;};
119 struct semaphore
{int a
;};
121 struct device_driver
{
123 struct bus_type
*bus
;
124 int (*probe
) (struct device
* dev
);
125 int (*remove
) (struct device
* dev
);
126 struct list_head devices
;
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
);
148 wait_queue_head_t wait
;
151 // windows lookaside list head
152 typedef void* kmem_cache_t
;
159 /* from mod_devicetable.h */
161 struct usb_device_id
{
162 /* which fields to match against? */
165 /* Used for product specific matches; range is inclusive */
171 /* Used for device class matches */
173 __u8 bDeviceSubClass
;
174 __u8 bDeviceProtocol
;
176 /* Used for interface class matches */
177 __u8 bInterfaceClass
;
178 __u8 bInterfaceSubClass
;
179 __u8 bInterfaceProtocol
;
181 /* not matched against */
182 kernel_ulong_t driver_info
;
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
197 /*------------------------------------------------------------------------*/
198 /* imported functions from top-level */
199 /*------------------------------------------------------------------------*/
201 //void zxprintf(char* fmt, ...);
202 //void zxsprintf(char *buffer, char* fmt, ...);
203 //int zxsnprintf(char *buffer, size_t s, char* fmt, ...);
205 /*------------------------------------------------------------------------*/
206 /* PCI structs (taken from linux/pci.h et al., but slightly modified) */
207 /*------------------------------------------------------------------------*/
219 void * dev_ext
; // link to Windows DeviceExtension
223 unsigned char number
;
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 */
234 struct list_head node
;
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 */
252 struct usbdevfs_hub_portinfo
258 /*------------------------------------------------------------------------*/
259 /* constant defines */
260 /*------------------------------------------------------------------------*/
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: "
271 #define SLAB_ATOMIC 0
272 #define PCI_ANY_ID (~0)
274 #define THIS_MODULE 0
275 //#define PAGE_SIZE 4096
279 #define CLONE_FILES 0
280 #define CLONE_SIGHAND 0
282 #define PF_IOTHREAD 0
285 #define USBDEVFS_HUB_PORTINFO 1234
289 #define PCI_COMMAND 0
290 #undef PCI_COMMAND_MASTER
291 #define PCI_COMMAND_MASTER 0
292 /*------------------------------------------------------------------------*/
293 /* Module/export macros */
294 /*------------------------------------------------------------------------*/
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)
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)
312 #define __setup(x,y) int setup_##y=(int)y
313 #define subsys_initcall(x) void subsys_##x(void){x();}
315 /*------------------------------------------------------------------------*/
317 /*------------------------------------------------------------------------*/
319 #define dev_get_drvdata(a) (a)->driver_data
320 #define dev_set_drvdata(a,b) (a)->driver_data=(b)
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
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))
333 /* The kernel macro for list_for_each_entry makes nonsense (have no clue
334 * why, this is just the same definition...) */
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))
344 /*------------------------------------------------------------------------*/
345 /* function wrapper macros */
346 /*------------------------------------------------------------------------*/
347 #define kmalloc(x,y) ExAllocatePool(PagedPool,x)
348 #define kfree(x) ExFreePool(x)
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)
357 /* Locks & friends */
359 #define DECLARE_MUTEX(x) struct semaphore x
360 #define init_MUTEX(x)
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)
367 #define spin_lock_irqsave(a,b) b=0
368 #define spin_unlock_irqrestore(a,b)
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")
374 #define local_irq_save(x) do {} while(0)
375 #define local_irq_restore(x) do {} while(0)
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)
385 #define down(x) do {} while(0)
386 #define up(x) do {} while(0)
387 #define down_trylock(a) 0
389 #define down_read(a) do {} while(0)
390 #define up_read(a) do {} while(0)
392 #define DECLARE_WAIT_QUEUE_HEAD(x) KEVENT x
394 #define DECLARE_COMPLETION(x) struct completion x
398 #define driver_unregister(a) do {} while(0)
399 #define put_device(a) do {} while(0)
403 #define to_pci_dev(n) container_of(n, struct pci_dev, dev)
405 #define pci_pool_create(a,b,c,d,e) (void*)1
407 #define pci_pool_alloc(a,b,c) my_pci_pool_alloc(a,b,c)
409 static void __inline__
*my_pci_pool_alloc(void* pool
, size_t size
,
410 dma_addr_t
*dma_handle
)
413 a
=kmalloc(size
,0); //FIXME
415 *dma_handle
=((u32
)a
)&0xfffffff;
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)
426 static void __inline__
*my_pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
427 dma_addr_t
*dma_handle
)
431 a
=kmalloc(size
+256,0); //FIXME
432 a
=(void*)(((int)a
+255)&~255); // 256 alignment
433 *dma_handle
=((u32
)a
)&0xfffffff;
438 #define pci_free_consistent(a,b,c,d) kfree(c)
439 #define pci_pool_destroy(a) do {} while(0)
441 #define pci_module_init(x) my_pci_module_init(x)
442 int my_pci_module_init(struct pci_driver
*x
);
444 #define pci_unregister_driver(a) do {} while(0)
446 #define bus_register(a) do {} while(0)
447 #define bus_unregister(a) do {} while(0)
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)
456 #define dma_alloc_coherent(a,b,c,d) NULL
457 #define dma_free_coherent(a,b,c,d) do {} while(0)
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)
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)
472 #define page_address(x) ((void*)(x/4096))
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
480 #define PCI_ROM_RESOURCE 0
481 #define IORESOURCE_IO 1
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
);
489 VOID
KeMemoryBarrier(VOID
);
491 #define mb() KeMemoryBarrier()
492 #define wmb() __asm__ __volatile__ ("": : :"memory")
493 #define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
495 #define in_interrupt() 0
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
*);
502 #define IRQ_HANDLED 1
504 #define INIT_WORK(a,b,c) (a)->func=b
506 #define set_current_state(a) do {} while(0)
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)
513 #define interruptible_sleep_on(a) my_interruptible_sleep_on(a)
514 void my_interruptible_sleep_on(PKEVENT evnt
);
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
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
);
525 #define yield() do {} while(0)
526 #define cpu_relax() do {} while(0)
528 #define WARN_ON(a) do {} while(0)
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))
538 kmem_cache_t
*my_kmem_cache_create(const char *tag
, size_t alloc_size
,
539 size_t offset
, unsigned long flags
,
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
);
547 /*------------------------------------------------------------------------*/
549 /*------------------------------------------------------------------------*/
551 #define LINUX_VERSION_CODE 0x020572
552 #define UTS_SYSNAME "XBOX"
553 #define UTS_RELEASE "----"
555 /* from linux/kernel.h */
556 #define max_t(type,x,y) \
557 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
559 #define min_t(type,x,y) \
560 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
562 #define container_of(ptr, type, member) ({ \
563 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
564 (type *)( (char *)__mptr - offsetof(type,member) );})
566 /* from linux/stddef.h */
569 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
571 /*------------------------------------------------------------------------*/
572 /* Conversion macros */
573 /*------------------------------------------------------------------------*/
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))
586 /*------------------------------------------------------------------------*/
588 /*------------------------------------------------------------------------*/
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
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)
611 #define PCI_DEVFN(a,b) 0
612 #define PCI_SLOT(a) 0
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
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.
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
629 /*------------------------------------------------------------------------*/
630 /* Stuff from kernel */
631 /*------------------------------------------------------------------------*/
635 //#include "linux/pci_ids.h"
637 /*------------------------------------------------------------------------*/
638 /* global variables */
639 /*------------------------------------------------------------------------*/
641 #define jiffies my_jiffies
642 extern int my_jiffies
;
643 #define current my_current
644 extern struct dummy_process
*my_current
;
646 extern struct list_head interrupt_list
;
648 /*------------------------------------------------------------------------*/
649 /* Function prototypes */
650 /*------------------------------------------------------------------------*/
651 void STDCALL
usb_hcd_pci_remove (struct pci_dev
*dev
);
653 #define my_wait_ms(x) wait_ms(x)
655 #define my_udelay(x) wait_ms(x)
656 #define udelay(x) my_udelay(x)
658 #define my_mdelay(x) wait_ms(1+x/1000);
659 #define mdelay(x) my_mdelay(x);
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
);
664 /*------------------------------------------------------------------------*/
665 /* Timer management */
666 /*------------------------------------------------------------------------*/
668 #define MAX_TIMERS 20
669 extern struct timer_list
*main_timer_list
[MAX_TIMERS
];
671 static void __inline__
init_timer(struct timer_list
* t
)
673 INIT_LIST_HEAD(&t
->timer_list
);
678 static void __inline__
add_timer(struct timer_list
* t
)
681 for(n
=0;n
<MAX_TIMERS
;n
++)
682 if (main_timer_list
[n
]==0)
684 main_timer_list
[n
]=t
;
689 static void __inline__
del_timer(struct timer_list
* t
)
692 for(n
=0;n
<MAX_TIMERS
;n
++)
693 if (main_timer_list
[n
]==t
)
695 main_timer_list
[n
]=0;
699 static void __inline__
del_timer_sync(struct timer_list
* t
)
702 for(n
=0;n
<MAX_TIMERS
;n
++)
703 if (main_timer_list
[n
]==t
)
705 main_timer_list
[n
]=0;
710 static void __inline__
mod_timer(struct timer_list
* t
, int ex
)
717 #define time_after_eq(a,b) \
718 (((long)(a) - (long)(b) >= 0))
720 /*------------------------------------------------------------------------*/
721 /* Device driver and process related stuff */
722 /*------------------------------------------------------------------------*/
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
){}
728 #define device_initialize(x) my_device_initialize(x)
729 void my_device_initialize(struct device
*dev
);
731 #define get_device(x) my_get_device(x)
732 struct device
*my_get_device(struct device
*dev
);
734 #define device_add(x) my_device_add(x)
735 int my_device_add(struct device
*dev
);
737 #define driver_register(x) my_driver_register(x)
738 int my_driver_register(struct device_driver
*driver
);
740 #define device_unregister(a) my_device_unregister(a)
741 int my_device_unregister(struct device
*dev
);
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)
747 #define schedule_timeout(x) my_schedule_timeout(x)
748 int my_schedule_timeout(int x
);
750 #define wake_up(x) my_wake_up(x)
751 void my_wake_up(PKEVENT
);
753 // cannot be mapped via macro due to collision with urb->complete
754 static void __inline__
complete(struct completion
*p
)
756 /* Wake up x->wait */
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
);
764 /*------------------------------------------------------------------------*/
765 /* PCI, simple and inlined... */
766 /*------------------------------------------------------------------------*/
769 /*------------------------------------------------------------------------*/
771 /*------------------------------------------------------------------------*/
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
);
778 #define free_irq(a,b) my_free_irq(a,b)
779 int free_irq(int irq
, void* p
);
784 int (*handler
)(int, void *, struct pt_regs
*);
791 // Exported to top level
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);
798 #define __KERNEL_DS 0x18