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 /*------------------------------------------------------------------------*/
211 unsigned char number
;
214 struct pci_device_id
{
215 __u32 vendor
, device
; /* Vendor and device ID or PCI_ANY_ID*/
216 __u32 subvendor
, subdevice
; /* Subsystem ID's or PCI_ANY_ID */
217 __u32
class, class_mask
; /* (class,subclass,prog-if) triplet */
218 kernel_ulong_t driver_data
; /* Data private to the driver */
222 struct list_head node
;
224 const struct pci_device_id
*id_table
; /* must be non-NULL for probe to be called */
225 int (*probe
) (struct pci_dev
*dev
, const struct pci_device_id
*id
); /* New device inserted */
226 void (*remove
) (struct pci_dev
*dev
); /* Device removed (NULL if not a hot-plug capable driver) */
227 int (*save_state
) (struct pci_dev
*dev
, u32 state
); /* Save Device Context */
228 int (*suspend
) (struct pci_dev
*dev
, u32 state
); /* Device suspended */
229 int (*resume
) (struct pci_dev
*dev
); /* Device woken up */
230 int (*enable_wake
) (struct pci_dev
*dev
, u32 state
, int enable
); /* Enable wake event */
240 struct usbdevfs_hub_portinfo
246 /*------------------------------------------------------------------------*/
247 /* constant defines */
248 /*------------------------------------------------------------------------*/
250 #define TASK_UNINTERRUPTIBLE 0
251 #define HZ 100 /* Don't rely on that... */
252 #define KERN_DEBUG "DBG: "
253 #define KERN_ERR "ERR: "
254 #define KERN_WARNING "WRN: "
255 #define KERN_INFO "INF: "
259 #define SLAB_ATOMIC 0
260 #define PCI_ANY_ID (~0)
262 #define THIS_MODULE 0
263 //#define PAGE_SIZE 4096
267 #define CLONE_FILES 0
268 #define CLONE_SIGHAND 0
270 #define PF_IOTHREAD 0
273 #define USBDEVFS_HUB_PORTINFO 1234
277 #define PCI_COMMAND 0
278 #undef PCI_COMMAND_MASTER
279 #define PCI_COMMAND_MASTER 0
280 /*------------------------------------------------------------------------*/
281 /* Module/export macros */
282 /*------------------------------------------------------------------------*/
284 #define MODULE_AUTHOR(a)
285 #define MODULE_DESCRIPTION(a)
286 #define MODULE_LICENSE(a)
287 #define MODULE_DEVICE_TABLE(type,name) void* module_table_##name=&name
292 #define __devinitdata
293 #define module_init(x) static void module_init_##x(void){ x();}
294 #define module_exit(x) void module_exit_##x(void){ x();}
295 #define EXPORT_SYMBOL_GPL(x)
296 #define EXPORT_SYMBOL(x)
298 #define __setup(x,y) int setup_##y=(int)y
299 #define subsys_initcall(x) void subsys_##x(void){x();}
301 /*------------------------------------------------------------------------*/
303 /*------------------------------------------------------------------------*/
305 #define dev_get_drvdata(a) (a)->driver_data
306 #define dev_set_drvdata(a,b) (a)->driver_data=(b)
308 #define __io_virt(x) ((void *)(x))
309 #define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
310 #define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
311 #define likely(x) (x)
312 #define unlikely(x) (x)
313 #define prefetch(x) 1
315 /* The kernel macro for list_for_each_entry makes nonsense (have no clue
316 * why, this is just the same definition...) */
318 #undef list_for_each_entry
319 #define list_for_each_entry(pos, head, member) \
320 for (pos = list_entry((head)->next, typeof(*pos), member), \
321 prefetch(pos->member.next); \
322 &pos->member != (head); \
323 pos = list_entry(pos->member.next, typeof(*pos), member), \
324 prefetch(pos->member.next))
326 /*------------------------------------------------------------------------*/
327 /* function wrapper macros */
328 /*------------------------------------------------------------------------*/
329 #define kmalloc(x,y) ExAllocatePool(PagedPool,x)
330 #define kfree(x) ExFreePool(x)
332 //#define sprintf(a,b,format, arg...) zxsprintf((a),(b),format, ## arg)
333 //#define snprintf(a,b,format, arg...) zxsnprintf((a),(b),format, ##arg)
334 //#define printk(format, arg...) zxprintf(format, ## arg)
335 #define snprintf(a,b,format, arg...) _snprintf((a),(b),format, ##arg)
336 #define printk(format, arg...) DPRINT1(format, ## arg)
337 #define BUG(...) do {} while(0)
339 /* Locks & friends */
341 #define DECLARE_MUTEX(x) struct semaphore x
342 #define init_MUTEX(x)
344 #define SPIN_LOCK_UNLOCKED 0
345 #define spin_lock_init(a) do {} while(0)
346 #define spin_lock(a) *(int*)a=1
347 #define spin_unlock(a) do {} while(0)
349 #define spin_lock_irqsave(a,b) b=0
350 #define spin_unlock_irqrestore(a,b)
353 #define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
354 #define local_irq_restore(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
356 #define local_irq_save(x) do {} while(0)
357 #define local_irq_restore(x) do {} while(0)
360 #define atomic_inc(x) *(x)+=1
361 #define atomic_dec(x) *(x)-=1
362 #define atomic_dec_and_test(x) (*(x)-=1,(*(x))==0)
363 #define atomic_set(x,a) *(x)=a
364 #define atomic_read(x) *(x)
365 #define ATOMIC_INIT(x) (x)
367 #define down(x) do {} while(0)
368 #define up(x) do {} while(0)
369 #define down_trylock(a) 0
371 #define down_read(a) do {} while(0)
372 #define up_read(a) do {} while(0)
374 #define DECLARE_WAIT_QUEUE_HEAD(x) int x
376 #define DECLARE_COMPLETION(x) struct completion x
380 #define driver_unregister(a) do {} while(0)
381 #define put_device(a) do {} while(0)
385 #define pci_pool_create(a,b,c,d,e) (void*)1
387 #define pci_pool_alloc(a,b,c) my_pci_pool_alloc(a,b,c)
389 static void __inline__
*my_pci_pool_alloc(void* pool
, size_t size
,
390 dma_addr_t
*dma_handle
)
393 a
=kmalloc(size
,0); //FIXME
395 *dma_handle
=((u32
)a
)&0xfffffff;
403 #define pci_pool_free(a,b,c) kfree(b)
404 #define pci_alloc_consistent(a,b,c) my_pci_alloc_consistent(a,b,c)
406 static void __inline__
*my_pci_alloc_consistent(struct pci_dev
*hwdev
, size_t size
,
407 dma_addr_t
*dma_handle
)
411 a
=kmalloc(size
+256,0); //FIXME
412 a
=(void*)(((int)a
+255)&~255); // 256 alignment
413 *dma_handle
=((u32
)a
)&0xfffffff;
418 #define pci_free_consistent(a,b,c,d) kfree(c)
419 #define pci_pool_destroy(a) do {} while(0)
421 #define pci_module_init(x) my_pci_module_init(x)
422 int my_pci_module_init(struct pci_driver
*x
);
424 #define pci_unregister_driver(a) do {} while(0)
426 #define bus_register(a) do {} while(0)
427 #define bus_unregister(a) do {} while(0)
429 #define dma_map_single(a,b,c,d) ((u32)(b)&0xfffffff)
430 #define dma_unmap_single(a,b,c,d) do {} while(0)
431 #define pci_unmap_single(a,b,c,d) do {} while(0)
432 #define dma_sync_single(a,b,c,d) do {} while(0)
433 #define dma_sync_sg(a,b,c,d) do {} while(0)
434 #define dma_map_sg(a,b,c,d) 0
435 #define dma_unmap_sg(a,b,c,d) do {} while(0)
437 #define usb_create_driverfs_dev_files(a) do {} while(0)
438 #define usb_create_driverfs_intf_files(a) do {} while(0)
439 #define sg_dma_address(x) ((u32)((x)->page*4096 + (x)->offset))
440 #define sg_dma_len(x) ((x)->length)
442 #define page_address(x) ((void*)(x/4096))
444 #define DMA_TO_DEVICE 0
445 #define DMA_FROM_DEVICE 0
446 #define PCI_DMA_TODEVICE
447 #define PCI_DMA_FROMDEVICE
448 #define PCI_DMA_TODEVICE
450 #define PCI_ROM_RESOURCE 0
451 #define IORESOURCE_IO 1
453 #define DECLARE_WAITQUEUE(a,b) wait_queue_head_t a=0
454 #define init_waitqueue_head(a) do {} while(0)
455 #define add_wait_queue(a,b) do {} while(0)
456 #define remove_wait_queue(a,b) do {} while(0)
458 #define wmb() __asm__ __volatile__ ("": : :"memory")
459 #define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory")
461 #define in_interrupt() 0
463 #define init_completion(x) (x)->done=0
464 #define wait_for_completion(x) my_wait_for_completion(x)
465 void my_wait_for_completion(struct completion
*);
468 #define IRQ_HANDLED 1
470 #define INIT_WORK(a,b,c) (a)->func=b
472 #define set_current_state(a) do {} while(0)
474 #define might_sleep() do {} while(0)
475 #define daemonize(a) do {} while(0)
476 #define allow_signal(a) do {} while(0)
477 #define wait_event_interruptible(x,y) do {} while(0)
478 #define flush_scheduled_work() do {} while(0)
479 #define refrigerator(x) do {} while(0)
480 #define signal_pending(x) 1 // fall through threads
481 #define complete_and_exit(a,b) return 0
483 #define kill_proc(a,b,c) 0
484 #define yield() do {} while(0)
485 #define cpu_relax() do {} while(0)
487 /*------------------------------------------------------------------------*/
489 /*------------------------------------------------------------------------*/
491 #define LINUX_VERSION_CODE 0x020572
492 #define UTS_SYSNAME "XBOX"
493 #define UTS_RELEASE "----"
495 /* from linux/kernel.h */
496 #define max_t(type,x,y) \
497 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
499 #define min_t(type,x,y) \
500 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
502 #define container_of(ptr, type, member) ({ \
503 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
504 (type *)( (char *)__mptr - offsetof(type,member) );})
506 /* from linux/stddef.h */
509 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
511 /*------------------------------------------------------------------------*/
512 /* Conversion macros */
513 /*------------------------------------------------------------------------*/
515 #define __constant_cpu_to_le32(x) (x)
516 #define cpu_to_le16(x) (x)
517 #define le16_to_cpu(x) (x)
518 #define cpu_to_le32(x) (x)
519 #define cpu_to_le32p(x) (*(__u32*)(x))
520 #define le32_to_cpup(x) (*(__u32*)(x))
521 #define le32_to_cpu(x) ((u32)x)
522 #define le16_to_cpus(x) do {} while (0)
523 #define le16_to_cpup(x) (*(__u16*)(x))
524 #define cpu_to_le16p(x) (*(__u16*)(x))
526 /*------------------------------------------------------------------------*/
528 /*------------------------------------------------------------------------*/
530 #define dev_printk(lvl,x,f,arg...) printk(f, ## arg)
531 #define dev_dbg(x,f,arg...) do {} while (0) //printk(f, ## arg)
532 #define dev_info(x,f,arg...) printk(f,## arg)
533 #define dev_warn(x,f,arg...) printk(f,## arg)
534 #define dev_err(x,f,arg...) printk(f,## arg)
535 #define pr_debug(x,f,arg...) printk(f,## arg)
536 #define usbprintk printk
540 #define dev_printk(lvl,x,f,arg...) do {} while (0)
541 #define dev_dbg(x,f,arg...) do {} while (0) //printk(f, ## arg)
542 #define dev_info(x,f,arg...) do {} while (0)
543 #define dev_warn(x,f,arg...) do {} while (0)
544 #define dev_err(x,f,arg...) do {} while (0)
545 #define pr_debug(x,f,arg...) do {} while (0)
551 #define PCI_DEVFN(a,b) 0
552 #define PCI_SLOT(a) 0
554 /*------------------------------------------------------------------------*/
555 /* Stuff from kernel */
556 /*------------------------------------------------------------------------*/
560 //#include "linux/pci_ids.h"
562 /*------------------------------------------------------------------------*/
563 /* global variables */
564 /*------------------------------------------------------------------------*/
566 #define jiffies my_jiffies
567 extern int my_jiffies
;
568 #define current my_current
569 extern struct dummy_process
*my_current
;
571 extern struct list_head interrupt_list
;
573 /*------------------------------------------------------------------------*/
574 /* Function prototypes */
575 /*------------------------------------------------------------------------*/
576 void STDCALL
usb_hcd_pci_remove (struct pci_dev
*dev
);
578 #define my_wait_ms(x) wait_ms(x)
580 #define my_udelay(x) wait_ms(x)
581 #define udelay(x) my_udelay(x)
583 #define my_mdelay(x) wait_ms(1+x/1000);
584 #define mdelay(x) my_mdelay(x);
586 #define pci_find_slot(a,b) my_pci_find_slot(a,b)
587 struct pci_dev
*my_pci_find_slot(int a
,int b
);
589 /*------------------------------------------------------------------------*/
590 /* Timer management */
591 /*------------------------------------------------------------------------*/
593 #define MAX_TIMERS 20
594 extern struct timer_list
*main_timer_list
[MAX_TIMERS
];
596 static void __inline__
init_timer(struct timer_list
* t
)
598 INIT_LIST_HEAD(&t
->timer_list
);
603 static void __inline__
add_timer(struct timer_list
* t
)
606 for(n
=0;n
<MAX_TIMERS
;n
++)
607 if (main_timer_list
[n
]==0)
609 main_timer_list
[n
]=t
;
614 static void __inline__
del_timer(struct timer_list
* t
)
617 for(n
=0;n
<MAX_TIMERS
;n
++)
618 if (main_timer_list
[n
]==t
)
620 main_timer_list
[n
]=0;
624 static void __inline__
del_timer_sync(struct timer_list
* t
)
627 for(n
=0;n
<MAX_TIMERS
;n
++)
628 if (main_timer_list
[n
]==t
)
630 main_timer_list
[n
]=0;
635 static void __inline__
mod_timer(struct timer_list
* t
, int ex
)
642 /*------------------------------------------------------------------------*/
643 /* Device driver and process related stuff */
644 /*------------------------------------------------------------------------*/
646 static int __inline__
usb_major_init(void){return 0;}
647 static void __inline__
usb_major_cleanup(void){}
648 static void __inline__
schedule_work(void* p
){}
650 #define device_initialize(x) my_device_initialize(x)
651 void my_device_initialize(struct device
*dev
);
653 #define get_device(x) my_get_device(x)
654 struct device
*my_get_device(struct device
*dev
);
656 #define device_add(x) my_device_add(x)
657 int my_device_add(struct device
*dev
);
659 #define driver_register(x) my_driver_register(x)
660 int my_driver_register(struct device_driver
*driver
);
662 #define device_unregister(a) my_device_unregister(a)
663 int my_device_unregister(struct device
*dev
);
665 #define DEVICE_ATTR(a,b,c,d) int xxx_##a
666 #define device_create_file(a,b) do {} while(0)
667 #define device_remove_file(a,b) do {} while(0)
669 #define schedule_timeout(x) my_schedule_timeout(x)
670 int my_schedule_timeout(int x
);
672 #define wake_up(x) my_wake_up(x)
673 void my_wake_up(void*);
675 // cannot be mapped via macro due to collision with urb->complete
676 static void __inline__
complete(struct completion
*p
)
678 /* Wake up x->wait */
683 #define kernel_thread(a,b,c) my_kernel_thread(a,b,c)
684 int my_kernel_thread(int (*handler
)(void*), void* parm
, int flags
);
686 /*------------------------------------------------------------------------*/
687 /* PCI, simple and inlined... */
688 /*------------------------------------------------------------------------*/
691 /*------------------------------------------------------------------------*/
693 /*------------------------------------------------------------------------*/
695 #define request_irq(a,b,c,d,e) my_request_irq(a,b,c,d,e)
696 int my_request_irq(unsigned int irq
,
697 int (*handler
)(int, void *, struct pt_regs
*),
698 unsigned long mode
, const char *desc
, void *data
);
700 #define free_irq(a,b) my_free_irq(a,b)
701 int free_irq(int irq
, void* p
);
706 int (*handler
)(int, void *, struct pt_regs
*);
713 // Exported to top level
715 void handle_irqs(int irq
);
716 void inc_jiffies(int);
717 void init_wrapper(void);
718 void do_all_timers(void);
720 #define __KERNEL_DS 0x18