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#ifndef _FW_GLUE_H 9#define _FW_GLUE_H 10 11 12#include <dpc.h> 13#include <stdint.h> 14#include <strings.h> 15 16 17#define device_printf(dev, a...) dprintf("firewire:" a) 18#define printf(a...) dprintf(a) 19#define KASSERT(cond,msg) do { \ 20 if (!cond) \ 21 panic msg; \ 22} while(0) 23 24#ifndef howmany 25#define howmany(x, y) (((x)+((y)-1))/(y)) // x/y的上界 26#endif 27#define rounddown(x, y) (((x)/(y))*(y)) // 比x小,y的最大的倍数 28#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ // 比x大,y的最小倍数 29#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ 30#define powerof2(x) ((((x)-1)&(x))==0) // 是否是2的次方 31 32typedef uint32_t bus_addr_t; 33typedef uint32_t bus_size_t; 34 35#define atomic_readandclear_int(ptr) atomic_get_and_set((int32*)(ptr), 0) 36#define atomic_set_int(ptr, value) atomic_or((int32 *)(ptr), value) 37 38#define mtx_lock mutex_lock 39#define mtx_unlock mutex_unlock 40#define mtx_destroy mutex_destroy 41#define mtx_init(lockaddr, name, type, opts) mutex_init(lockaddr, name) 42 43#define wakeup(i) release_sem_etc(i->Sem, 0, B_RELEASE_IF_WAITING_ONLY | B_RELEASE_ALL) 44 45#define splfw() 0 46#define splx(s) (void)s 47 48#define hz 1000000LL 49 50#define DELAY(n) snooze(n) 51 52#define OWRITE(sc, offset, value) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset)) = value) 53#define OREAD(sc, offset) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset))) 54 55#define MAX_CARDS 4 56extern dpc_module_info *gDpc; 57 58#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 59 60#endif /*_FW_GLUE_H*/ 61