xref: /haiku/headers/private/firewire/fwglue.h (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /*
2  * Copyright 2007, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *	JiSheng Zhang
7  */
8 
9 #ifndef _FW_GLUE_H
10 #define _FW_GLUE_H
11 
12 #include <stdint.h>
13 #include <dpc.h>
14 
15 #define device_printf(dev, a...) dprintf("firewire:" a)
16 #define printf(a...) dprintf(a)
17 #define KASSERT(cond,msg) do { \
18 	if (!cond) \
19 		panic msg; \
20 } while(0)
21 
22 #ifndef howmany
23 #define howmany(x, y)   (((x)+((y)-1))/(y)) // x/y的上界
24 #endif
25 #define rounddown(x, y) (((x)/(y))*(y)) // 比x小,y的最大的倍数
26 #define roundup(x, y)   ((((x)+((y)-1))/(y))*(y))  /* to any y */ // 比x大,y的最小倍数
27 #define roundup2(x, y)  (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
28 #define powerof2(x)     ((((x)-1)&(x))==0) // 是否是2的次方
29 
30 typedef uint32_t bus_addr_t;
31 typedef uint32_t bus_size_t;
32 
33 #define atomic_readandclear_int(ptr) atomic_set((int32 *)(ptr), 0)
34 #define atomic_set_int(ptr, value) atomic_or((int32 *)(ptr), value)
35 
36 #define mtx_lock mutex_lock
37 #define mtx_unlock mutex_unlock
38 #define mtx_destroy mutex_destroy
39 #define mtx_init(lockaddr, name, type, opts) mutex_init(lockaddr, name)
40 
41 #define splfw() 0
42 #define splx(s)
43 
44 #define hz 1000000LL
45 
46 #define DELAY(n)	snooze(n)
47 
48 #define OWRITE(sc, offset, value) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset)) = value)
49 #define OREAD(sc, offset) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset)))
50 
51 #define MAX_CARDS 4
52 extern dpc_module_info *gDpc;
53 
54 #define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
55 
56 #endif /*_FW_GLUE_H*/
57