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 30typedef uint32_t bus_addr_t; 31typedef 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 wakeup(i) release_sem_etc(i->Sem, 0, B_RELEASE_IF_WAITING_ONLY | B_RELEASE_ALL) 42 43#define splfw() 0 44#define splx(s) (void)s 45 46#define hz 1000000LL 47 48#define DELAY(n) snooze(n) 49 50#define OWRITE(sc, offset, value) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset)) = value) 51#define OREAD(sc, offset) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset))) 52 53#define MAX_CARDS 4 54extern dpc_module_info *gDpc; 55 56#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 57 58#endif /*_FW_GLUE_H*/ 59