]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/twe/twe_compat.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / twe / twe_compat.h
1 /*-
2  * Copyright (c) 2000 Michael Smith
3  * Copyright (c) 2003 Paul Saab
4  * Copyright (c) 2003 Vinod Kashyap
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  *
29  * $FreeBSD$
30  */
31 /*
32  * Portability and compatibility interfaces.
33  */
34
35 #ifdef __FreeBSD__
36 /******************************************************************************
37  * FreeBSD
38  */
39 #define TWE_SUPPORTED_PLATFORM
40
41 #include <sys/param.h>
42 #include <sys/endian.h>
43 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
46 #include <sys/lock.h>
47 #include <sys/module.h>
48 #include <sys/mutex.h>
49 #include <sys/sysctl.h>
50 #include <sys/sx.h>
51
52 #include <sys/bio.h>
53 #include <sys/bus.h>
54 #include <sys/conf.h>
55 #include <sys/disk.h>
56 #include <sys/stat.h>
57
58 #include <machine/bus.h>
59 #include <machine/resource.h>
60 #include <sys/rman.h>
61
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcivar.h>
64
65 #include <geom/geom_disk.h>
66
67 #define TWE_DRIVER_NAME         twe
68 #define TWED_DRIVER_NAME        twed
69 #define TWE_MALLOC_CLASS        M_TWE
70
71 /* 
72  * Wrappers for bus-space actions
73  */
74 #define TWE_CONTROL(sc, val)            bus_write_4((sc)->twe_io, 0x0, (u_int32_t)val)
75 #define TWE_STATUS(sc)                  (u_int32_t)bus_read_4((sc)->twe_io, 0x4)
76 #define TWE_COMMAND_QUEUE(sc, val)      bus_write_4((sc)->twe_io, 0x8, (u_int32_t)val)
77 #define TWE_RESPONSE_QUEUE(sc)          (TWE_Response_Queue)bus_read_4((sc)->twe_io, 0xc)
78
79 /*
80  * FreeBSD-specific softc elements
81  */
82 #define TWE_PLATFORM_SOFTC                                                              \
83     bus_dmamap_t                twe_cmdmap;     /* DMA map for command */                               \
84     u_int32_t                   twe_cmdphys;    /* address of command in controller space */            \
85     device_t                    twe_dev;                /* bus device */                \
86     struct cdev *twe_dev_t;             /* control device */            \
87     struct resource             *twe_io;                /* register interface window */ \
88     bus_dma_tag_t               twe_parent_dmat;        /* parent DMA tag */            \
89     bus_dma_tag_t               twe_buffer_dmat;        /* data buffer DMA tag */       \
90     bus_dma_tag_t               twe_cmd_dmat;           /* command buffer DMA tag */    \
91     bus_dma_tag_t               twe_immediate_dmat;     /* command buffer DMA tag */    \
92     struct resource             *twe_irq;               /* interrupt */                 \
93     void                        *twe_intr;              /* interrupt handle */          \
94     struct intr_config_hook     twe_ich;                /* delayed-startup hook */      \
95     void                        *twe_cmd;               /* command structures */        \
96     void                        *twe_immediate;         /* immediate commands */        \
97     bus_dmamap_t                twe_immediate_map;                                      \
98     struct mtx                  twe_io_lock;                                            \
99     struct sx                   twe_config_lock;
100
101 /*
102  * FreeBSD-specific request elements
103  */
104 #define TWE_PLATFORM_REQUEST                                                                            \
105     bus_dmamap_t                tr_dmamap;      /* DMA map for data */                                  \
106     u_int32_t                   tr_dataphys;    /* data buffer base address in controller space */
107
108 /*
109  * Output identifying the controller/disk
110  */
111 #define twe_printf(sc, fmt, args...)    device_printf(sc->twe_dev, fmt , ##args)
112 #define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args)
113
114 #define TWE_IO_LOCK(sc)                 mtx_lock(&(sc)->twe_io_lock)
115 #define TWE_IO_UNLOCK(sc)               mtx_unlock(&(sc)->twe_io_lock)
116 #define TWE_IO_ASSERT_LOCKED(sc)        mtx_assert(&(sc)->twe_io_lock, MA_OWNED)
117 #define TWE_CONFIG_LOCK(sc)             sx_xlock(&(sc)->twe_config_lock)
118 #define TWE_CONFIG_UNLOCK(sc)           sx_xunlock(&(sc)->twe_config_lock)
119 #define TWE_CONFIG_ASSERT_LOCKED(sc)    sx_assert(&(sc)->twe_config_lock, SA_XLOCKED)
120
121 #endif /* FreeBSD */
122
123 #ifndef TWE_SUPPORTED_PLATFORM
124 #error platform not supported
125 #endif