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 * #include <standard-GPL-header.h>
18 /*------------------------------------------------------------------------*/
20 /*------------------------------------------------------------------------*/
21 #include "cromwell_types.h"
23 typedef unsigned int __u32
;
25 typedef unsigned short __u16
;
27 typedef unsigned char __u8
;
32 typedef u32 dma_addr_t
;
34 typedef int spinlock_t
;
42 typedef int irqreturn_t
;
43 typedef unsigned long kernel_ulong_t
;
45 typedef int wait_queue_head_t
;
46 /*------------------------------------------------------------------------*/
47 /* Stuff from xbox/linux environment */
48 /*------------------------------------------------------------------------*/
55 #define NULL ((void*)0)
56 extern void * memset(void *,int,unsigned int);
57 extern void * memcpy(void *,const void *,unsigned int);
59 extern char * strcpy(char *,const char *);
61 static inline char * strcpy(char * dest
,const char *src
)
69 : "=&S" (d0
), "=&D" (d1
), "=&a" (d2
)
70 :"0" (src
),"1" (dest
) : "memory");
74 extern size_t strlen(const char *);
76 extern int memcmp(const void *,const void *,unsigned int);
90 /*------------------------------------------------------------------------*/
92 /*------------------------------------------------------------------------*/
95 void (*function
)(unsigned long);
98 struct list_head timer_list
;
102 void (*func
)(void *);
106 struct bus_type
*bus
;
109 struct device_driver
* driver
;
111 struct device
*parent
;
112 struct list_head driver_list
;
113 void (*release
)(struct device
* dev
);
115 struct class_device
{int a
;};
116 struct semaphore
{int a
;};
118 struct device_driver
{
120 struct bus_type
*bus
;
121 int (*probe
) (struct device
* dev
);
122 int (*remove
) (struct device
* dev
);
123 struct list_head devices
;
128 int (*match
)(struct device
* dev
, struct device_driver
* drv
);
129 struct device
* (*add
) (struct device
* parent
, char * bus_id
);
130 int (*hotplug
) (struct device
*dev
, char **envp
,
131 int num_envp
, char *buffer
, int buffer_size
);
145 wait_queue_head_t wait
;
148 /* from mod_devicetable.h */
150 struct usb_device_id
{
151 /* which fields to match against? */
154 /* Used for product specific matches; range is inclusive */
160 /* Used for device class matches */
162 __u8 bDeviceSubClass
;
163 __u8 bDeviceProtocol
;
165 /* Used for interface class matches */
166 __u8 bInterfaceClass
;
167 __u8 bInterfaceSubClass
;
168 __u8 bInterfaceProtocol
;
170 /* not matched against */
171 kernel_ulong_t driver_info
;
174 /* Some useful macros to use to create struct usb_device_id */
175 #define USB_DEVICE_ID_MATCH_VENDOR 0x0001
176 #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
177 #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
178 #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
179 #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
180 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
181 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
182 #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
183 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
184 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
186 /*------------------------------------------------------------------------*/
187 /* imported functions from top-level */
188 /*------------------------------------------------------------------------*/
190 //void zxprintf(char* fmt, ...);
191 //void zxsprintf(char *buffer, char* fmt, ...);
192 //int zxsnprintf(char *buffer, size_t s, char* fmt, ...);
194 /*------------------------------------------------------------------------*/
195 /* PCI structs (taken from linux/pci.h et al., but slightly modified) */
196 /*------------------------------------------------------------------------*/
208 void * dev_ext
; // link to Windows DeviceExtension
212 unsigned char number
;
215 struct pci_device_id
{
216 __u32 vendor
, device
; /* Vendor and device ID or PCI_ANY_ID*/
217 __u32 subvendor
, subdevice
; /* Subsystem ID's or PCI_ANY_ID */
218 __u32
class, class_mask
; /* (class,subclass,prog-if) triplet */
219 kernel_ulong_t driver_data
; /* Data private to the driver */
223 struct list_head node
;
225 const struct pci_device_id
*id_table
; /* must be non-NULL for probe to be called */
226 int (*probe
) (struct pci_dev
*dev
, const struct pci_device_id
*id
); /* New device inserted */
227 void (*remove
) (struct pci_dev
*dev
); /* Device removed (NULL if not a hot-plug capable driver) */
228 int (*save_state
) (struct pci_dev
*dev
, u32 state
); /* Save Device Context */
229 int (*suspend
) (struct pci_dev
*dev
, u32 state
); /* Device suspended */
230 int (*resume
) (struct pci_dev
*dev
); /* Device woken up */
231 int (*enable_wake
) (struct pci_dev
*dev
, u32 state
, int enable
); /* Enable wake event */
241 struct usbdevfs_hub_portinfo
247 /*------------------------------------------------------------------------*/
248 /* constant defines */
249 /*------------------------------------------------------------------------*/
251 #define TASK_UNINTERRUPTIBLE 0
252 #define HZ 100 /* Don't rely on that... */
253 #define KERN_DEBUG "DBG: "
254 #define KERN_ERR "ERR: "
255 #define KERN_WARNING "WRN: "
256 #define KERN_INFO "INF: "
260 #define SLAB_ATOMIC 0
261 #define PCI_ANY_ID (~0)
263 #define THIS_MODULE 0
264 //#define PAGE_SIZE 4096
268 #define CLONE_FILES 0
269 #define CLONE_SIGHAND 0
271 #define PF_IOTHREAD 0
274 #define USBDEVFS_HUB_PORTINFO 1234
278 #define PCI_COMMAND 0
279 #undef PCI_COMMAND_MASTER
280 #define PCI_COMMAND_MASTER 0
281 /*------------------------------------------------------------------------*/
282 /* Module/export macros */
283 /*------------------------------------------------------------------------*/
285 #define MODULE_AUTHOR(a)
286 #define MODULE_DESCRIPTION(a)
287 #define MODULE_LICENSE(a)
288 #define MODULE_DEVICE_TABLE(type,name) void* module_table_##name=&name
293 #define __devinitdata
294 #define module_init(x) static void module_init_##x(void){ x();}
295 #define module_exit(x) void module_exit_##x(void){ x();}
296 #define EXPORT_SYMBOL_GPL(x)
297 #define EXPORT_SYMBOL(x)
299 #define __setup(x,y) int setup_##y=(int)y
300 #define subsys_initcall(x) void subsys_##x(void){x();}
302 /*------------------------------------------------------------------------*/
304 /*------------------------------------------------------------------------*/
306 #define dev_get_drvdata(a) (a)->driver_data
307 #define dev_set_drvdata(a,b) (a)->driver_data=(b)
309 #define __io_virt(x) ((void *)(x))
310 #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
311 #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
312 #define likely(x) (x)
313 #define unlikely(x) (x)
314 #define prefetch(x) 1
316 /* The kernel macro for list_for_each_entry makes nonsense (have no clue
317 * why, this is just the same definition...) */
319 #undef list_for_each_entry
320 #define list_for_each_entry(pos, head, member) \
321 for (pos = list_entry((head)->next, typeof(*pos), member), \
322 prefetch(pos->member.next); \
323 &pos->member != (head); \
324 pos = list_entry(pos->member.next, typeof(*pos), member), \
325 prefetch(pos->member.next))
327 /*------------------------------------------------------------------------*/
328 /* function wrapper macros */
329 /*------------------------------------------------------------------------*/
330 #define kmalloc(x,y) ExAllocatePool(PagedPool,x)
331 #define kfree(x) ExFreePool(x)
333 //#define sprintf(a,b,format, arg...) zxsprintf((a),(b),format, ## arg)
334 //#define snprintf(a,b,format, arg...) zxsnprintf((a),(b),format, ##arg)
335 //#define printk(format, arg...) zxprintf(format, ## arg)
336 #define snprintf(a,b,format, arg...) _snprintf((a),(b),format, ##arg)
337 #define printk(format, arg...) DPRINT1(format, ## arg)
338 #define BUG(...) do {} while(0)
340 /* Locks & friends */
342 #define DECLARE_MUTEX(x) struct semaphore x
343 #define init_MUTEX(x)
345 #define SPIN_LOCK_UNLOCKED 0
346 #define spin_lock_init(a) do {} while(0)
347 #define spin_lock(a) *(int*)a=1
348 #define spin_unlock(a) do {} while(0)
350 #define spin_lock_irqsave(a,b) b=0
351 #define spin_unlock_irqrestore(a,b)
354 #define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
355 #define local_irq_restore(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
357 #define local_irq_save(x) do {} while(0)
358 #define local_irq_restore(x) do {} while(0)
361 #define atomic_inc(x) *(x)+=1
362 #define atomic_dec(x) *(x)-=1
363 #define atomic_dec_and_test(x) (*(x)-=1,(*(x))==0)
364 #define atomic_set(x,a) *(x)=a
365 #define atomic_read(x) *(x)
366 #define ATOMIC_INIT(x) (x)
368 #define down(x) do {} while(0)
369 #define up(x) do {} while(0)
370 #define down_trylock(a) 0
372 #define down_read(a) do {} while(0)
373 #define up_read(a) do {} while(0)
375 #define DECLARE_WAIT_QUEUE_HEAD(x) int x
377 #define DECLARE_COMPLETION(x) struct completion x
381 #define driver_unregister(a) do {} while(0)
382 #define put_device(a) do {} while(0)
386 #define pci_pool_create(a,b,c,d,e) (void*)1
388 #define pci_pool_alloc(a,b,c) my_pci_pool_alloc(a,b,c)
390 static void __inline__
*my_pci_pool_alloc(void* pool
, size_t size
,
391 dma_addr_t
*dma_handle
)
394 a
=kmalloc(size
,0); //FIXME
396 *dma_handle
=((u32
)a
)&0xfffffff;
404 #define pci_pool_free(a,b,c) kfree(b)
405 #define pci_alloc_consistent(a,b,c) my_pci_alloc_consistent(a,b,c)
407 static void __inline__
*my_pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
408 dma_addr_t
*dma_handle
)
412 a
=kmalloc(size
+256,0); //FIXME
413 a
=(void*)(((int)a
+255)&~255); // 256 alignment
414 *dma_handle
=((u32
)a
)&0xfffffff;
419 #define pci_free_consistent(a,b,c,d) kfree(c)
420 #define pci_pool_destroy(a) do {} while(0)
422 #define pci_module_init(x) my_pci_module_init(x)
423 int my_pci_module_init(struct pci_driver
*x
);
425 #define pci_unregister_driver(a) do {} while(0)
427 #define bus_register(a) do {} while(0)
428 #define bus_unregister(a) do {} while(0)
430 #define dma_map_single(a,b,c,d) ((u32)(b)&0xfffffff)
431 #define dma_unmap_single(a,b,c,d) do {} while(0)
432 #define pci_unmap_single(a,b,c,d) do {} while(0)
433 #define dma_sync_single(a,b,c,d) do {} while(0)
434 #define dma_sync_sg(a,b,c,d) do {} while(0)
435 #define dma_map_sg(a,b,c,d) 0
436 #define dma_unmap_sg(a,b,c,d) do {} while(0)
438 #define usb_create_driverfs_dev_files(a) do {} while(0)
439 #define usb_create_driverfs_intf_files(a) do {} while(0)
440 #define sg_dma_address(x) ((u32)((x)->page*4096 + (x)->offset))
441 #define sg_dma_len(x) ((x)->length)
443 #define page_address(x) ((void*)(x/4096))
445 #define DMA_TO_DEVICE 0
446 #define DMA_FROM_DEVICE 0
447 #define PCI_DMA_TODEVICE
448 #define PCI_DMA_FROMDEVICE
449 #define PCI_DMA_TODEVICE
451 #define PCI_ROM_RESOURCE 0
452 #define IORESOURCE_IO 1
454 #define DECLARE_WAITQUEUE(a,b) wait_queue_head_t a=0
455 #define init_waitqueue_head(a) do {} while(0)
456 #define add_wait_queue(a,b) do {} while(0)
457 #define remove_wait_queue(a,b) do {} while(0)
459 #define wmb() __asm__ __volatile__ ("": : :"memory")
460 #define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
462 #define in_interrupt() 0
464 #define init_completion(x) (x)->done=0
465 #define wait_for_completion(x) my_wait_for_completion(x)
466 void my_wait_for_completion(struct completion
*);
469 #define IRQ_HANDLED 1
471 #define INIT_WORK(a,b,c) (a)->func=b
473 #define set_current_state(a) do {} while(0)
475 #define might_sleep() do {} while(0)
476 #define daemonize(a) do {} while(0)
477 #define allow_signal(a) do {} while(0)
478 #define wait_event_interruptible(x,y) do {} while(0)
480 #define interruptible_sleep_on(a) my_interruptible_sleep_on(a)
481 void my_interruptible_sleep_on(int a
);
483 #define flush_scheduled_work() do {} while(0)
484 #define refrigerator(x) do {} while(0)
485 #define signal_pending(x) 1 // fall through threads
486 #define complete_and_exit(a,b) return 0
488 //#define kill_proc(a,b,c) 0
489 #define kill_proc(a,b,c) my_kill_proc(a, b, c);
490 int my_kill_proc(int pid
, int signal
, int unk
);
492 #define yield() do {} while(0)
493 #define cpu_relax() do {} while(0)
495 /*------------------------------------------------------------------------*/
497 /*------------------------------------------------------------------------*/
499 #define LINUX_VERSION_CODE 0x020572
500 #define UTS_SYSNAME "XBOX"
501 #define UTS_RELEASE "----"
503 /* from linux/kernel.h */
504 #define max_t(type,x,y) \
505 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
507 #define min_t(type,x,y) \
508 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
510 #define container_of(ptr, type, member) ({ \
511 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
512 (type *)( (char *)__mptr - offsetof(type,member) );})
514 /* from linux/stddef.h */
517 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
519 /*------------------------------------------------------------------------*/
520 /* Conversion macros */
521 /*------------------------------------------------------------------------*/
523 #define __constant_cpu_to_le32(x) (x)
524 #define cpu_to_le16(x) (x)
525 #define le16_to_cpu(x) (x)
526 #define cpu_to_le32(x) (x)
527 #define cpu_to_le32p(x) (*(__u32*)(x))
528 #define le32_to_cpup(x) (*(__u32*)(x))
529 #define le32_to_cpu(x) ((u32)x)
530 #define le16_to_cpus(x) do {} while (0)
531 #define le16_to_cpup(x) (*(__u16*)(x))
532 #define cpu_to_le16p(x) (*(__u16*)(x))
534 /*------------------------------------------------------------------------*/
536 /*------------------------------------------------------------------------*/
538 #define dev_printk(lvl,x,f,arg...) printk(f, ## arg)
539 #define dev_dbg(x,f,arg...) printk(f, ## arg)
540 #define dev_info(x,f,arg...) printk(f,## arg)
541 #define dev_warn(x,f,arg...) printk(f,## arg)
542 #define dev_err(x,f,arg...) printk(f,## arg)
543 #define pr_debug(x,f,arg...) printk(f,## arg)
544 #define usbprintk printk
548 #define dev_printk(lvl,x,f,arg...) do {} while (0)
549 #define dev_dbg(x,f,arg...) do {} while (0) //printk(f, ## arg)
550 #define dev_info(x,f,arg...) do {} while (0)
551 #define dev_warn(x,f,arg...) do {} while (0)
552 #define dev_err(x,f,arg...) do {} while (0)
553 #define pr_debug(x,f,arg...) do {} while (0)
559 #define PCI_DEVFN(a,b) 0
560 #define PCI_SLOT(a) 0
562 /*------------------------------------------------------------------------*/
563 /* Stuff from kernel */
564 /*------------------------------------------------------------------------*/
568 //#include "linux/pci_ids.h"
570 /*------------------------------------------------------------------------*/
571 /* global variables */
572 /*------------------------------------------------------------------------*/
574 #define jiffies my_jiffies
575 extern int my_jiffies
;
576 #define current my_current
577 extern struct dummy_process
*my_current
;
579 extern struct list_head interrupt_list
;
581 /*------------------------------------------------------------------------*/
582 /* Function prototypes */
583 /*------------------------------------------------------------------------*/
584 void STDCALL
usb_hcd_pci_remove (struct pci_dev
*dev
);
586 #define my_wait_ms(x) wait_ms(x)
588 #define my_udelay(x) wait_ms(x)
589 #define udelay(x) my_udelay(x)
591 #define my_mdelay(x) wait_ms(1+x/1000);
592 #define mdelay(x) my_mdelay(x);
594 #define pci_find_slot(a,b) my_pci_find_slot(a,b)
595 struct pci_dev
*my_pci_find_slot(int a
,int b
);
597 /*------------------------------------------------------------------------*/
598 /* Timer management */
599 /*------------------------------------------------------------------------*/
601 #define MAX_TIMERS 20
602 extern struct timer_list
*main_timer_list
[MAX_TIMERS
];
604 static void __inline__
init_timer(struct timer_list
* t
)
606 INIT_LIST_HEAD(&t
->timer_list
);
611 static void __inline__
add_timer(struct timer_list
* t
)
614 for(n
=0;n
<MAX_TIMERS
;n
++)
615 if (main_timer_list
[n
]==0)
617 main_timer_list
[n
]=t
;
622 static void __inline__
del_timer(struct timer_list
* t
)
625 for(n
=0;n
<MAX_TIMERS
;n
++)
626 if (main_timer_list
[n
]==t
)
628 main_timer_list
[n
]=0;
632 static void __inline__
del_timer_sync(struct timer_list
* t
)
635 for(n
=0;n
<MAX_TIMERS
;n
++)
636 if (main_timer_list
[n
]==t
)
638 main_timer_list
[n
]=0;
643 static void __inline__
mod_timer(struct timer_list
* t
, int ex
)
650 /*------------------------------------------------------------------------*/
651 /* Device driver and process related stuff */
652 /*------------------------------------------------------------------------*/
654 static int __inline__
usb_major_init(void){return 0;}
655 static void __inline__
usb_major_cleanup(void){}
656 static void __inline__
schedule_work(void* p
){}
658 #define device_initialize(x) my_device_initialize(x)
659 void my_device_initialize(struct device
*dev
);
661 #define get_device(x) my_get_device(x)
662 struct device
*my_get_device(struct device
*dev
);
664 #define device_add(x) my_device_add(x)
665 int my_device_add(struct device
*dev
);
667 #define driver_register(x) my_driver_register(x)
668 int my_driver_register(struct device_driver
*driver
);
670 #define device_unregister(a) my_device_unregister(a)
671 int my_device_unregister(struct device
*dev
);
673 #define DEVICE_ATTR(a,b,c,d) int xxx_##a
674 #define device_create_file(a,b) do {} while(0)
675 #define device_remove_file(a,b) do {} while(0)
677 #define schedule_timeout(x) my_schedule_timeout(x)
678 int my_schedule_timeout(int x
);
680 #define wake_up(x) my_wake_up(x)
681 void my_wake_up(void*);
683 // cannot be mapped via macro due to collision with urb->complete
684 static void __inline__
complete(struct completion
*p
)
686 /* Wake up x->wait */
691 #define kernel_thread(a,b,c) my_kernel_thread(a,b,c)
692 int my_kernel_thread(int STDCALL (*handler
)(void*), void* parm
, int flags
);
694 /*------------------------------------------------------------------------*/
695 /* PCI, simple and inlined... */
696 /*------------------------------------------------------------------------*/
699 /*------------------------------------------------------------------------*/
701 /*------------------------------------------------------------------------*/
703 #define request_irq(a,b,c,d,e) my_request_irq(a,b,c,d,e)
704 int my_request_irq(unsigned int irq
,
705 int (*handler
)(int, void *, struct pt_regs
*),
706 unsigned long mode
, const char *desc
, void *data
);
708 #define free_irq(a,b) my_free_irq(a,b)
709 int free_irq(int irq
, void* p
);
714 int (*handler
)(int, void *, struct pt_regs
*);
721 // Exported to top level
723 void handle_irqs(int irq
);
724 void inc_jiffies(int);
725 void init_wrapper(struct pci_dev
*pci_dev
);
726 void do_all_timers(void);
728 #define __KERNEL_DS 0x18