unifdef -U__FreeBSD__ -D__NetBSD__, et cetera.

This commit is contained in:
dyoung 2009-08-07 00:10:53 +00:00
parent ec63b8722d
commit cb637e784d
1 changed files with 1 additions and 557 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fw_port.h,v 1.32 2009/04/20 09:56:07 mschuett Exp $ */
/* $NetBSD: fw_port.h,v 1.33 2009/08/07 00:10:53 dyoung Exp $ */
/*
* Copyright (c) 2004 KIYOHARA Takashi
* All rights reserved.
@ -31,559 +31,6 @@
#ifdef _KERNEL
#if defined(__FreeBSD__)
#ifdef __DragonFly__
#define OS_STR "DragonFly"
#define OS_VER __DragonFly_cc_version
#define OS_VER_STR "DragonFly-1"
#define PROJECT_STR "DragonFly Project"
#else
#define OS_STR "FreeBSD"
#define OS_VER __FreeBSD_version
#define OS_VER_STR "FreeBSD-5"
#define PROJECT_STR "FreeBSD Project"
#endif
#if defined(__DragonFly__) || __FreeBSD_version < 500000
#define fw_dev_t dev_t
#else
#define fw_dev_t struct cdev *
#endif
#if defined(__DragonFly__) || __FreeBSD_version < 500000
#define fw_dev2unit(x) ((minor(x) & 0xff) | (minor(x) >> 8))
#define fw_unit2minor(x) (((x) & 0xff) | (((x) << 8) & ~0xffff))
#else
#define fw_dev2unit(x) dev2unit(x)
#define fw_unit2minor(x) unit2minor(x)
#endif
#define fw_timevalcmp(tv1, tv2, op) timevalcmp((tv1), (tv2), op)
#define fw_timevalsub(tv1, tv2) timevalsub((tv1), (tv2))
#define fw_get_nameunit(dev) device_get_nameunit((dev))
#define fw_get_unit(dev) device_get_unit((dev))
#define fw_printf(dev, ...) device_printf((dev), __VA_ARGS__)
/* atomic macros */
#define fw_atomic_set_int(P, V) atomic_set_int((P), (V))
#define fw_atomic_readandclear_int(p) atomic_readandclear_int((p))
/* mutex macros */
#include <sys/mutex.h>
typedef struct mtx fw_mtx_t;
#define fw_mtx_init(mutex, name, type, opts) \
mtx_init(mutex, name, type, opts)
#define fw_mtx_lock(mutex) mtx_lock(mutex)
#define fw_mtx_unlock(mutex) mtx_unlock(mutex)
#define fw_mtx_destroy(mutex) mtx_destroy(mutex)
#define fw_mtx_assert(mutex, what) \
mtx_assert(mutex, what)
#define fw_msleep(ident, mtx, priority, wmesg, timo) \
msleep(ident, mtx, priority, wmesg, timo);
/* taskqueue macros */
#include <sys/taskqueue.h>
typedef struct task fw_task_t;
#define FW_TASK_INIT(task, priority, func, context) \
TASK_INIT((task), (priority), (func), (context))
#define fw_taskqueue_enqueue(queue, task) \
taskqueue_enqueue((queue), (task))
#define fw_taskqueue_create_fast(name, mflags, enqueue, taskqueue) \
taskqueue_create_fast((name), (mflags), (enqueue), (taskqueue))
#define fw_taskqueue_start_threads(taskqueue, n, x, fmt, ...) \
taskqueue_start_threads((taskqueue), (n), (x), (fmt), ...)
/* kthread macros */
#ifdef __DragonFly__
typedef d_thread_t fw_thread_t;
typedef d_thread_t fw_proc_t;
#define fw_kthread_create(func, arg, newpp, fmt, ...) \
kthread_create(func, arg, newpp, fmt, __VA_ARGS__)
#define fw_kthread_exit(x) kthread_exit()
#elif __FreeBSD_version >= 500000
typedef struct thread fw_thread_t;
typedef struct thread fw_proc_t;
#define fw_kthread_create(func, arg, newpp, fmt, ...) \
kthread_create(func, arg, newpp, 0, 0, fmt, __VA_ARGS__)
#define fw_kthread_exit(ecode) kthread_exit((ecode))
#else
typedef struct proc fw_thread_t;
typedef struct proc fw_proc_t;
#define fw_kthread_create(func, arg, newpp, fmt, ...) \
kproc_create(func, arg, newpp, fmt, __VA_ARGS__)
#define fw_kthread_exit(ecode) kproc_exit((ecode))
#endif
/* callout macros */
#if defined(__DragonFly__) || __FreeBSD_version < 500000
#define fw_callout_init(c) callout_init((c), 0)
#else
#define fw_callout_init(c) callout_init(c, 1 /* mpsafe */)
#endif
#define fw_callout_reset(c, ticks, func, arg) \
callout_reset((c), (ticks), (func), (arg))
#define fw_callout_stop(c) callout_stop((c))
/* bus_dma macros */
typedef bus_dma_tag_t fw_bus_dma_tag_t;
#if defined(__FreeBSD__) && __FreeBSD_version >= 501102
#define fw_bus_dma_tag_create(t, \
a, b, laddr, haddr, ffunc, farg, s, ns, mxss, f, lfunc, larg, tp)\
bus_dma_tag_create((t), (a), (b), (laddr), (haddr), \
(ffunc), (farg), (s), (ns), (mxss), (f), (lfunc), (larg), (tp))
#else
#define fw_bus_dma_tag_create(t, a, b, \
laddr, haddr, ffunc, farg, s, ns, mxss, f, lfunc, larg, tp) \
bus_dma_tag_create((t), (a), (b), (laddr), (haddr), \
(ffunc), (farg), (s), (ns), (mxss), (f), (tp))
#endif
#define fw_bus_dma_tag_destroy(t) \
bus_dma_tag_destroy((t))
#define fw_bus_dmamap_create(t, f, mp) \
bus_dmamap_create((t), 0, (mp))
#define fw_bus_dmamap_destroy((t), (m)) \
bus_dmamap_destroy((t), (m))
#define fw_bus_dmamap_load(t, m, b, l, func, a, f) \
bus_dmamap_load((t), (m), (b), (l), (func), (a), 0)
#define fw_bus_dmamap_load_mbuf(t, m, b, func, a, f) \
bus_dmamap_load((t), (m), (b), (func), (a), 0)
#define fw_bus_dmamap_unload(t, m) \
bus_dmamap_unload((t), (m))
#if __FreeBSD_version < 500000
#define fw_bus_dmamap_sync(t, m, op) \
do { \
switch ((op)) { \
(BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE): \
bus_dmamap_sync((t), (m), BUS_DMASYNC_PREWRITE);\
bus_dmamap_sync((t), (m), BUS_DMASYNC_PREREAD); \
break; \
(BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE): \
/* BUS_DMASYNC_POSTWRITE is probably a no-op. */\
bus_dmamap_sync((t), (m), BUS_DMASYNC_POSTREAD);\
break; \
default: \
bus_dmamap_sync((t), (m), (op)); \
} \
} while (/*CONSTCOND*/0)
#else
#define fw_bus_dmamap_sync(t, m, op) \
bus_dmamap_sync((t), (m), (op))
#endif
#define fw_bus_dmamem_alloc(t, vp, f, mp) \
bus_dmamem_alloc((t), (vp), (f), (mp))
#define fw_bus_dmamem_free(t, v, m) \
bus_dmamem_free((t), (v), (m))
#define fw_config_pending_incr()
#define fw_config_pending_decr()
#define splfw() splimp()
#define splfwnet() splimp()
#define splfwsbp() splcam()
#ifdef __DragonFly__
#include <sys/select.h>
#elif __FreeBSD_version >= 500000
#include <sys/selinfo.h>
#else
#include <sys/select.h>
#endif
#define FW_KASSERT(expression, str) \
KASSERT(expression, str)
#ifdef __DragonFly__
#define M_DONTWAIT MB_DONTWAIT
#endif
/*
* fw attach macro for FreeBSD
*/
#define FW_ATTACH(dname) \
static int \
__CONCAT(dname,_attach)(device_t dev)
#define FW_ATTACH_START(dname, sc, fwa) \
struct __CONCAT(dname,_softc) *sc = \
((struct __CONCAT(dname,_softc) *)device_get_softc(dev)); \
__unused struct fw_attach_args *fwa = \
device_get_ivars(dev)
#define FW_ATTACH_RETURN(r) return (r)
/*
* fw detach macro for FreeBSD
*/
#define FW_DETACH(dname) \
static int \
__CONCAT(dname,_detach)(device_t dev)
#define FW_DETACH_START(dname, sc) \
struct __CONCAT(dname,_softc) *sc = \
((struct __CONCAT(dname,_softc) *)device_get_softc(dev))
/*
* fw open macro for FreeBSD
*/
#define FW_OPEN(dname) \
int \
__CONCAT(dname,_open)(fw_dev_t dev, int flags, int fmt, fw_proc_t td)
#define FW_OPEN_START \
int unit = DEV2UNIT(dev); \
__unused struct firewire_softc *sc = \
devclass_get_softc(firewire_devclass, unit)
/*
* fw close macro for FreeBSD
*/
#define FW_CLOSE(dname) \
int \
__CONCAT(dname,_close)(fw_dev_t dev, int flags, \
int fmt, fw_proc_t td)
#define FW_CLOSE_START
/*
* fw read macro for FreeBSD
*/
#define FW_READ(dname) \
int \
__CONCAT(dname,_read)(fw_dev_t dev, struct uio *uio, int ioflag)
#define FW_READ_START
/*
* fw write macro for FreeBSD
*/
#define FW_WRITE(dname) \
int \
__CONCAT(dname,_write)(fw_dev_t dev, struct uio *uio, int ioflag)
#define FW_WRITE_START
/*
* fw ioctl macro for FreeBSD
*/
#define FW_IOCTL(dname) \
int \
__CONCAT(dname,_ioctl) \
(fw_dev_t dev, u_long cmd, void *data, int flag, fw_proc_t td)
#define FW_IOCTL_START \
int unit = DEV2UNIT(dev); \
__unused struct firewire_softc *sc = \
devclass_get_softc(firewire_devclass, unit)
/*
* fw poll macro for FreeBSD
*/
#define FW_POLL(dname) \
int \
__CONCAT(dname,_poll)(fw_dev_t dev, int events, fw_proc_t td)
#define FW_POLL_START
/*
* fw mmap macro for FreeBSD
*/
#if defined(__DragonFly__) || __FreeBSD_version < 500102
#define FW_MMAP(dname) \
int \
__CONCAT(dname,_mmap)(fw_dev_t dev, vm_offset_t offset, int nproto)
#else
#define FW_MMAP(dname) \
int \
__CONCAT(dname,_mmap) \
(fw_dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nproto)
#endif
#define FW_MMAP_START
/*
* fw strategy macro for FreeBSD
*/
#define FW_STRATEGY_START \
fw_dev_t dev = bp->bio_dev; \
int unit = DEV2UNIT(dev); \
__unused struct firewire_softc *sc = \
devclass_get_softc(firewire_devclass, unit)
/*
* if macro for FreeBSD
*/
#define IF_DETACH_START(dname, sc) \
struct __CONCAT(dname,_softc) *sc = \
(struct __CONCAT(dname,_softc) *)device_get_softc(dev)
#define IF_IOCTL_START(dname, sc) \
struct __CONCAT(dname,_softc) *sc = \
((struct fwip_eth_softc *)ifp->if_softc)->fwip
#define IF_INIT(dname) \
static void \
__CONCAT(dname,_init)(void *arg)
#define IF_INIT_START(dname, sc, ifp) \
struct __CONCAT(dname,_softc) *sc = \
((struct fwip_eth_softc *)arg)->fwip; \
struct ifnet *ifp = (sc)->fw_softc.fwip_ifp
#define IF_INIT_RETURN(r) return
#define IF_STOP(dname) \
static void \
__CONCAT(dname,_stop)(struct __CONCAT(dname,_softc) *fwip)
#define IF_STOP_START(dname, ifp, sc) \
struct ifnet *ifp = (sc)->fw_softc.fwip_ifp;
/*
* fwohci macro for FreeBSD
*/
#define FWOHCI_DETACH() \
int \
fwohci_detach(struct fwohci_softc *sc, device_t dev)
#define FWOHCI_DETACH_START
#define FWOHCI_DETACH_END
#define FWOHCI_INIT_END
/*
* firewire macro for FreeBSD
*/
#define FIREWIRE_ATTACH_START \
device_t pa = device_get_parent(dev); \
struct firewire_comm *fc = (struct firewire_comm *)device_get_softc(pa)
#define FWDEV_DESTROYDEV(sc) \
do { \
int err; \
if ((err = fwdev_destroydev((sc))) != 0) \
return err; \
} while (/*CONSTCOND*/0)
#define FIREWIRE_GENERIC_ATTACH \
do { \
/* Locate our children */ \
bus_generic_probe(dev); \
\
/* launch attachement of the added children */ \
bus_generic_attach(dev); \
} while (/*CONSTCOND*/0)
#define FIREWIRE_GENERIC_DETACH \
do { \
int err; \
if ((err = bus_generic_detach(dev)) != 0) \
return err; \
} while (/*CONSTCOND*/0)
#define FIREWIRE_SBP_ATTACH \
do { \
fwa.fwdev = fwdev; \
fwdev->sbp = device_add_child(fc->bdev, fwa.name, -1); \
if (fwdev->sbp) { \
device_set_ivars(fwdev->sbp, &fwa); \
device_probe_and_attach(fwdev->sbp); \
} \
} while (/*CONSTCOND*/0)
#define FIREWIRE_SBP_DETACH \
do { \
if (device_detach(fwdev->sbp) != 0) \
return; \
} while (/*CONSTCOND*/0)
#define FIREWIRE_CHILDREN_FOREACH_FUNC(func, fdc) \
do { \
device_t *devlistp; \
int i, devcnt; \
\
if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) { \
for( i = 0 ; i < devcnt ; i++) \
if (device_get_state(devlistp[i]) >= \
DS_ATTACHED) { \
(fdc) = device_get_softc(devlistp[i]);\
if ((fdc)->func != NULL) \
(fdc)->func((fdc)); \
} \
free(devlistp, M_TEMP); \
} \
} while (/*CONSTCOND*/0)
/*
* sbp macro for FreeBSD
*/
#define SBP_ATTACH_START \
struct cam_devq *devq; \
\
memset(sbp, 0, sizeof(struct sbp_softc)); \
sbp->fd.dev = dev
#define SBP_SCSIBUS_ATTACH \
do { \
sbp->sim = cam_sim_alloc(sbp_action, sbp_poll, "sbp", sbp, \
device_get_unit(dev), \
&sbp->mtx, \
/*untagged*/ 1, \
/*tagged*/ SBP_QUEUE_LEN - 1, \
devq); \
\
if (sbp->sim == NULL) { \
cam_simq_free(devq); \
return ENXIO; \
} \
\
SBP_LOCK(sbp); \
if (xpt_bus_register(sbp->sim, /*bus*/0) != CAM_SUCCESS) \
goto fail; \
\
if (xpt_create_path( \
&sbp->path, xpt_periph, cam_sim_path(sbp->sim), \
CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {\
xpt_bus_deregister(cam_sim_path(sbp->sim)); \
goto fail; \
} \
xpt_async(AC_BUS_RESET, sbp->path, /*arg*/ NULL); \
SBP_UNLOCK(sbp); \
} while (/*CONSTCOND*/0)
#define SBP_DEVICE(d) ((d)->path)
#define SBP_DEVICE_FREEZE(d, x) xpt_freeze_devq((d)->path, (x))
#define SBP_DEVICE_THAW(d, x) xpt_release_devq((d)->path, (x), TRUE)
#define SBP_BUS_FREEZE(b) \
do { \
if (((b)->sim->flags & SIMQ_FREEZED) == 0) { \
xpt_freeze_simq((b)->sim, /*count*/1); \
(b)->sim->flags |= SIMQ_FREEZED; \
} \
} while (/*CONSTCOND*/0)
#define SBP_BUS_THAW(b) \
do { \
xpt_release_simq((b)->sim, /*run queue*/TRUE); \
(b)->sim->flags &= ~SIMQ_FREEZED; \
} while (/*CONSTCOND*/0)
#define SBP_DEVICE_PREATTACH()
/*
* fwip macro for FreeBSD
*/
#define FWIP_ATTACH_START \
int unit = device_get_unit(dev);\
struct fw_hwaddr *hwaddr;
#define FWIP_ATTACH_SETUP \
do { \
fwip->fw_softc.fwip_ifp = if_alloc(IFT_IEEE1394); \
hwaddr = &IFP2FWC(fwip->fw_softc.fwip_ifp)->fc_hwaddr; \
} while (/*CONSTCOND*/0)
#define FWDEV_MAKEDEV(sc) fwdev_makedev(sc)
#define FIREWIRE_IFATTACH(ifp, ha) \
firewire_ifattach((ifp), (ha))
#define FIREWIRE_IFDETACH(ifp) \
do { \
firewire_ifdetach(ifp); \
if_free(ifp); \
} while (/*CONSTCOND*/0)
#define FIREWIRE_BUSRESET(ifp) firewire_busreset((ifp))
#define FIREWIRE_INPUT(ifp, m, src) \
firewire_input((ifp), (m), (src))
#define FWIP_INIT(sc) fwip_init(&(sc)->fw_softc)
#define FWIP_STOP(sc) fwip_stop((sc))
#define FIREWIRE_IOCTL(ifp, cmd, data) \
firewire_ioctl((ifp), (cmd), (data))
#define IF_INITNAME(ifp, dev, unit) \
if_initname((ifp), device_get_name((dev)), (unit));
#define SET_IFFUNC(ifp, start, ioctl, init, stop) \
do { \
(ifp)->if_start = (start); \
(ifp)->if_ioctl = (ioctl); \
(ifp)->if_init = (init); \
} while (/*CONSTCOND*/0)
/*
* fwdev macro for FreeBSD
*/
#define FWDEV_OPEN_START \
if (DEV_FWMEM(dev)) \
return fwmem_open(dev, flags, fmt, td)
#define FWDEV_CLOSE_START \
if (DEV_FWMEM(dev)) \
return fwmem_close(dev, flags, fmt, td)
#define FWDEV_READ_START \
if (DEV_FWMEM(dev)) \
return (physio(dev, uio, ioflag))
#define FWDEV_WRITE_START \
if (DEV_FWMEM(dev)) \
return (physio(dev, uio, ioflag))
#define FWDEV_IOCTL_START \
if (DEV_FWMEM(dev)) \
return fwmem_ioctl(dev, cmd, data, flag, td)
#define FWDEV_IOCTL_REDIRECT fc->ioctl(dev, cmd, data, flag, td)
#define FWDEV_POLL_START \
if (DEV_FWMEM(dev)) \
return fwmem_poll(dev, events, td)
#if defined(__DragonFly__) || __FreeBSD_version < 500102
#define FWDEV_MMAP_START \
if (DEV_FWMEM(dev)) \
return fwmem_mmap(dev, offset, nproto)
#else
#define FWDEV_MMAP_START \
if (DEV_FWMEM(dev)) \
return fwmem_mmap(dev, offset, paddr, nproto)
#endif
#define FWDEV_STRATEGY_START \
if (DEV_FWMEM(dev)) { \
fwmem_strategy(bp); \
return; \
}
#define XS_REQ_INVALID CAM_REQ_INVALID
#define XS_SCSI_BUS_RESET CAM_SCSI_BUS_RESET
#define XS_BDR_SENT CAM_BDR_SENT
#define XS_DEV_NOT_THERE CAM_DEV_NOT_THERE
#define XS_CMD_TIMEOUT CAM_CMD_TIMEOUT
#define XS_REQUEUE_REQ CAM_REQUEUE_REQ
#define XS_REQ_CMP CAM_REQ_CMP
#define XS_REQ_CMP_ERR CAM_REQ_CMP_ERR
#define XS_UA_ABORT CAM_UA_ABORT
#define XS_SENSE (CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID)
typedef union ccb sbp_scsi_xfer;
typedef struct scsi_inquiry_data sbp_scsi_inquiry_data;
#define SCSI_XFER_TARGET(x) ((x)->ccb_h.target_id)
#define SCSI_XFER_LUN(x) ((x)->ccb_h.target_lun)
#define SCSI_XFER_ERROR(x) ((x)->ccb_h.status)
#define SCSI_XFER_DIR(x) ((x)->ccb_h.flags & CAM_DIR_MASK)
#define SCSI_XFER_DATA_IN CAM_DIR_IN
#define SCSI_XFER_CALLOUT(x) ((x)->ccb_h.timeout_ch)
#define SCSI_XFER_TIMEOUT(x) ((x)->ccb_h.timeout)
#define SCSI_XFER_OPECODE(x) ((x)->csio.cdb_io.cdb_bytes[0])
#define SCSI_XFER_STATUS(x) ((x)->csio.scsi_status)
#define SCSI_XFER_EVPD(x) ((x)->csio.cdb_io.cdb_bytes[1] & SI_EVPD)
#define SCSI_XFER_CMDLEN(x) ((x)->csio.cdb_len)
#define SCSI_XFER_CMD(x) \
(((x)->csio.ccb_h.flags & CAM_CDB_POINTER) ?\
(void *)(x)->csio.cdb_io.cdb_ptr : \
(void *)&(x)->csio.cdb_io.cdb_bytes)
#define SCSI_XFER_DATALEN(x) ((x)->csio.dxfer_len)
#define SCSI_XFER_DATA(x) ((x)->csio.data_ptr)
#define SCSI_XFER_SENSELEN(x) ((x)->csio.sense_len)
#define SCSI_SENSE_DATA(x) (&(x)->csio.sense_data)
#define SCSI_INQUIRY_DATA(x) ((x)->csio.data_ptr)
#define SCSI_XFER_FUNCCODE(x) ((x)->ccb_h.func_code)
#define SCSI_XFER_10BCMD_DUMP(x) \
((x)->csio.cdb_io.cdb_bytes[0]), \
((x)->csio.cdb_io.cdb_bytes[1]), \
((x)->csio.cdb_io.cdb_bytes[2]), \
((x)->csio.cdb_io.cdb_bytes[3]), \
((x)->csio.cdb_io.cdb_bytes[4]), \
((x)->csio.cdb_io.cdb_bytes[5]), \
((x)->csio.cdb_io.cdb_bytes[6]), \
((x)->csio.cdb_io.cdb_bytes[7]), \
((x)->csio.cdb_io.cdb_bytes[8]), \
((x)->csio.cdb_io.cdb_bytes[9])
#define SCSI_XFER_REQUEST_COMPLETE(x)
#define SCSI_TRANSFER_DONE(x) xpt_done((x))
#ifdef SID_TYPE
#undef SID_TYPE
#define SID_TYPE 0x1f
#endif
#define NOT_LUN_WILDCARD(l) ((l) != CAM_LUN_WILDCARD)
#define CAM_XFER_FLAGS(x) ((x)->csio.ccb_h.flags)
#define mstohz(ms) \
(__predict_false((ms) >= 0x20000) ? \
(((ms) + 0u) / 1000u) * hz : \
(((ms) + 0u) * hz) / 1000u)
#elif defined(__NetBSD__)
#define OS_STR "NetBSD"
#define OS_VER __NetBSD_Version__
#define OS_VER_STR "NetBSD-2"
@ -1358,8 +805,5 @@ typedef struct scsipi_inquiry_data sbp_scsi_inquiry_data;
#define kdb_active 0
#endif
#endif
#if defined(__NetBSD__)
#define vm_offset_t void *
#endif
#endif