twe(4): Sync with FreeBSD.
[dragonfly.git] / sys / dev / raid / twe / twe_compat.h
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 2000 Michael Smith
a062d8a7
HP
3 * Copyright (c) 2003 Paul Saab
4 * Copyright (c) 2003 Vinod Kashyap
984263bc
MD
5 * Copyright (c) 2000 BSDi
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
f21d89e9 29 * $FreeBSD: src/sys/dev/twe/twe_compat.h,v 1.17 2012/11/17 01:52:19 svnexp Exp $
984263bc
MD
30 */
31/*
32 * Portability and compatibility interfaces.
33 */
34
984263bc
MD
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/malloc.h>
38#include <sys/kernel.h>
f21d89e9 39#include <sys/lock.h>
0a62b1be 40#include <sys/sysctl.h>
c2b68912 41#include <sys/buf2.h>
984263bc
MD
42#include <sys/bus.h>
43#include <sys/conf.h>
44#include <sys/disk.h>
45#include <sys/stat.h>
1f7ab7c9 46#include <sys/rman.h>
a062d8a7
HP
47#include <sys/devicestat.h>
48
1f2de5d4
MD
49#include <bus/pci/pcireg.h>
50#include <bus/pci/pcivar.h>
984263bc 51
c2b68912
SW
52#define TWE_DRIVER_NAME twe
53#define TWED_DRIVER_NAME twed
54#define TWE_MALLOC_CLASS M_TWE
984263bc
MD
55
56/*
57 * Wrappers for bus-space actions
58 */
f21d89e9
SW
59#define TWE_CONTROL(sc, val) bus_write_4((sc)->twe_io, 0x0, (u_int32_t)val)
60#define TWE_STATUS(sc) (u_int32_t)bus_read_4((sc)->twe_io, 0x4)
61#define TWE_COMMAND_QUEUE(sc, val) bus_write_4((sc)->twe_io, 0x8, (u_int32_t)val)
62#define TWE_RESPONSE_QUEUE(sc) bus_read_4((sc)->twe_io, 0xc)
984263bc
MD
63
64/*
65 * FreeBSD-specific softc elements
66 */
67#define TWE_PLATFORM_SOFTC \
c2b68912
SW
68 bus_dmamap_t twe_cmdmap; /* DMA map for command */ \
69 u_int32_t twe_cmdphys; /* address of command in controller space */ \
984263bc 70 device_t twe_dev; /* bus device */ \
b13267a5 71 cdev_t twe_dev_t; /* control device */ \
984263bc 72 struct resource *twe_io; /* register interface window */ \
984263bc
MD
73 bus_dma_tag_t twe_parent_dmat; /* parent DMA tag */ \
74 bus_dma_tag_t twe_buffer_dmat; /* data buffer DMA tag */ \
c2b68912
SW
75 bus_dma_tag_t twe_cmd_dmat; /* command buffer DMA tag */ \
76 bus_dma_tag_t twe_immediate_dmat; /* command buffer DMA tag */ \
984263bc
MD
77 struct resource *twe_irq; /* interrupt */ \
78 void *twe_intr; /* interrupt handle */ \
0a62b1be 79 struct intr_config_hook twe_ich; /* delayed-startup hook */ \
c2b68912
SW
80 void *twe_cmd; /* command structures */ \
81 void *twe_immediate; /* immediate commands */ \
82 bus_dmamap_t twe_immediate_map; \
0a62b1be 83 struct sysctl_ctx_list sysctl_ctx; \
f21d89e9
SW
84 struct sysctl_oid *sysctl_tree; \
85 struct lock twe_io_lock; \
86 struct lock twe_config_lock;
984263bc
MD
87
88/*
89 * FreeBSD-specific request elements
90 */
91#define TWE_PLATFORM_REQUEST \
984263bc
MD
92 bus_dmamap_t tr_dmamap; /* DMA map for data */ \
93 u_int32_t tr_dataphys; /* data buffer base address in controller space */
94
95/*
96 * Output identifying the controller/disk
97 */
98#define twe_printf(sc, fmt, args...) device_printf(sc->twe_dev, fmt , ##args)
99#define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args)
100
f21d89e9
SW
101#define TWE_IO_LOCK(sc) lockmgr(&(sc)->twe_io_lock, LK_EXCLUSIVE)
102#define TWE_IO_UNLOCK(sc) lockmgr(&(sc)->twe_io_lock, LK_RELEASE)
103#define TWE_CONFIG_LOCK(sc) lockmgr(&(sc)->twe_config_lock, LK_EXCLUSIVE)
104#define TWE_CONFIG_UNLOCK(sc) lockmgr(&(sc)->twe_config_lock, LK_RELEASE)
105#define TWE_CONFIG_ASSERT_LOCKED(sc) KKASSERT(lockowned(&(sc)->twe_config_lock))
106
107/*
108 * XXX
109 *
110 * Mimics FreeBSD's mtx_assert() behavior.
111 * We might want a global lockassert() function in the future.
112 */
113static __inline void
114twe_lockassert(struct lock *lockp)
115{
116 if (panicstr == NULL && !dumping)
117 KKASSERT(lockstatus(lockp, curthread) != 0);
118}