Merge from vendor branch GCC:
[dragonfly.git] / sys / dev / raid / twe / twe_compat.h
1 /*-
2  * Copyright (c) 2000 Michael Smith
3  * Copyright (c) 2000 BSDi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/sys/dev/twe/twe_compat.h,v 1.1.2.3 2002/03/07 09:57:02 msmith Exp $
28  * $DragonFly: src/sys/dev/raid/twe/twe_compat.h,v 1.9 2004/05/19 22:52:48 dillon Exp $
29  */
30 /*
31  * Portability and compatibility interfaces.
32  */
33
34 #ifdef __DragonFly__
35 /******************************************************************************
36  * DragonFly
37  */
38 #define TWE_SUPPORTED_PLATFORM
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/malloc.h>
43 #include <sys/kernel.h>
44 #include <sys/sysctl.h>
45
46 #include <sys/bus.h>
47 #include <sys/conf.h>
48 #include <sys/disk.h>
49 #include <sys/stat.h>
50
51 #include <machine/bus_pio.h>
52 #include <machine/bus.h>
53 #include <machine/resource.h>
54 #include <sys/rman.h>
55
56 #include <bus/pci/pcireg.h>
57 #include <bus/pci/pcivar.h>
58
59 /*
60  * These macros allows us to build a version of the driver which can 
61  * safely be loaded into a kernel which already contains a 'twe' driver,
62  * and which will override it in all things.
63  *
64  * All public symbols must be listed here.
65  */
66 #ifdef TWE_OVERRIDE
67 #define twe_setup               Xtwe_setup
68 #define twe_init                Xtwe_init
69 #define twe_deinit              Xtwe_deinit
70 #define twe_intr                Xtwe_intr
71 #define twe_submit_bio          Xtwe_submit_bio
72 #define twe_ioctl               Xtwe_ioctl
73 #define twe_describe_controller Xtwe_describe_controller
74 #define twe_print_controller    Xtwe_print_controller
75 #define twe_enable_interrupts   Xtwe_enable_interrupts
76 #define twe_disable_interrupts  Xtwe_disable_interrupts
77 #define twe_attach_drive        Xtwe_attach_drive
78 #define twed_intr               Xtwed_intr
79 #define twe_allocate_request    Xtwe_allocate_request
80 #define twe_free_request        Xtwe_free_request
81 #define twe_map_request         Xtwe_map_request
82 #define twe_unmap_request       Xtwe_unmap_request
83 #define twe_describe_code       Xtwe_describe_code
84 #define twe_table_status        Xtwe_table_status
85 #define twe_table_unitstate     Xtwe_table_unitstate
86 #define twe_table_unittype      Xtwe_table_unittype
87 #define twe_table_aen           Xtwe_table_aen
88 #define TWE_DRIVER_NAME         Xtwe
89 #define TWED_DRIVER_NAME        Xtwed
90 #define TWE_MALLOC_CLASS        M_XTWE
91 #else
92 #define TWE_DRIVER_NAME         twe
93 #define TWED_DRIVER_NAME        twed
94 #define TWE_MALLOC_CLASS        M_TWE
95 #endif
96
97 /* 
98  * Wrappers for bus-space actions
99  */
100 #define TWE_CONTROL(sc, val)            bus_space_write_4(sc->twe_btag, sc->twe_bhandle, 0x0, (u_int32_t)val)
101 #define TWE_STATUS(sc)                  (u_int32_t)bus_space_read_4(sc->twe_btag, sc->twe_bhandle, 0x4)
102 #define TWE_COMMAND_QUEUE(sc, val)      bus_space_write_4(sc->twe_btag, sc->twe_bhandle, 0x8, (u_int32_t)val)
103 #define TWE_RESPONSE_QUEUE(sc)          (TWE_Response_Queue)bus_space_read_4(sc->twe_btag, sc->twe_bhandle, 0xc)
104
105 /*
106  * FreeBSD-specific softc elements
107  */
108 #define TWE_PLATFORM_SOFTC                                                              \
109     device_t                    twe_dev;                /* bus device */                \
110     struct resource             *twe_io;                /* register interface window */ \
111     bus_space_handle_t          twe_bhandle;            /* bus space handle */          \
112     bus_space_tag_t             twe_btag;               /* bus space tag */             \
113     bus_dma_tag_t               twe_parent_dmat;        /* parent DMA tag */            \
114     bus_dma_tag_t               twe_buffer_dmat;        /* data buffer DMA tag */       \
115     struct resource             *twe_irq;               /* interrupt */                 \
116     void                        *twe_intr;              /* interrupt handle */          \
117     struct intr_config_hook     twe_ich;                /* delayed-startup hook */      \
118     struct sysctl_ctx_list      sysctl_ctx;                                             \
119     struct sysctl_oid           *sysctl_tree;
120
121 /*
122  * FreeBSD-specific request elements
123  */
124 #define TWE_PLATFORM_REQUEST                                                                            \
125     bus_dmamap_t                tr_cmdmap;      /* DMA map for command */                               \
126     u_int32_t                   tr_cmdphys;     /* address of command in controller space */            \
127     bus_dmamap_t                tr_dmamap;      /* DMA map for data */                                  \
128     u_int32_t                   tr_dataphys;    /* data buffer base address in controller space */
129
130 /*
131  * Output identifying the controller/disk
132  */
133 #define twe_printf(sc, fmt, args...)    device_printf(sc->twe_dev, fmt , ##args)
134 #define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args)
135
136 #if defined(__DragonFly__) || __FreeBSD_version < 500003
137 # include <machine/clock.h>
138
139 # include <sys/buf.h>                   /* old buf style */
140 # include <sys/proc.h>
141 # include <sys/buf2.h>
142 typedef struct buf                      twe_bio;
143 typedef struct buf_queue_head           twe_bioq;
144 # define TWE_BIO_QINIT(bq)              bufq_init(&bq);
145 # define TWE_BIO_QINSERT(bq, bp)        bufq_insert_tail(&bq, bp)
146 # define TWE_BIO_QFIRST(bq)             bufq_first(&bq)
147 # define TWE_BIO_QREMOVE(bq, bp)        bufq_remove(&bq, bp)
148 # define TWE_BIO_IS_READ(bp)            ((bp)->b_flags & B_READ)
149 # define TWE_BIO_DATA(bp)               (bp)->b_data
150 # define TWE_BIO_LENGTH(bp)             (bp)->b_bcount
151 # define TWE_BIO_LBA(bp)                (bp)->b_pblkno
152 # define TWE_BIO_SOFTC(bp)              (bp)->b_dev->si_drv1
153 # define TWE_BIO_UNIT(bp)               *(int *)((bp)->b_dev->si_drv2)
154 # define TWE_BIO_SET_ERROR(bp, err)     do { (bp)->b_error = err; (bp)->b_flags |= B_ERROR;} while(0)
155 # define TWE_BIO_HAS_ERROR(bp)          ((bp)->b_flags & B_ERROR)
156 # define TWE_BIO_RESID(bp)              (bp)->b_resid
157 # define TWE_BIO_DONE(bp)               biodone(bp)
158 # define TWE_BIO_STATS_START(bp)        devstat_start_transaction(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats)
159 # define TWE_BIO_STATS_END(bp)          devstat_end_transaction_buf(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats, bp)
160 #else
161 # include <sys/bio.h>
162 typedef struct bio                      twe_bio;
163 typedef struct bio_queue_head           twe_bioq;
164 # define TWE_BIO_QINIT(bq)              bioq_init(&bq);
165 # define TWE_BIO_QINSERT(bq, bp)        bioq_insert_tail(&bq, bp)
166 # define TWE_BIO_QFIRST(bq)             bioq_first(&bq)
167 # define TWE_BIO_QREMOVE(bq, bp)        bioq_remove(&bq, bp)
168 # define TWE_BIO_IS_READ(bp)            ((bp)->bio_cmd == BIO_READ)
169 # define TWE_BIO_DATA(bp)               (bp)->bio_data
170 # define TWE_BIO_LENGTH(bp)             (bp)->bio_bcount
171 # define TWE_BIO_LBA(bp)                (bp)->bio_pblkno
172 # define TWE_BIO_SOFTC(bp)              (bp)->bio_dev->si_drv1
173 # define TWE_BIO_UNIT(bp)               *(int *)((bp)->bio_dev->si_drv2)
174 # define TWE_BIO_SET_ERROR(bp, err)     do { (bp)->bio_error = err; (bp)->bio_flags |= BIO_ERROR;} while(0)
175 # define TWE_BIO_HAS_ERROR(bp)          ((bp)->bio_flags & BIO_ERROR)
176 # define TWE_BIO_RESID(bp)              (bp)->bio_resid
177 # define TWE_BIO_DONE(bp)               biodone(bp)
178 # define TWE_BIO_STATS_START(bp)        devstat_start_transaction(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats)
179 # define TWE_BIO_STATS_END(bp)          devstat_end_transaction_bio(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats, bp)
180 #endif
181
182 #endif /* DragonFly */
183
184 #ifndef TWE_SUPPORTED_PLATFORM
185 #error platform not supported
186 #endif