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: src/sys/dev/twe/twe_compat.h,v 1.1.2.5 2004/04/07 22:18:00 vkashyap Exp $ 30 * $DragonFly: src/sys/dev/raid/twe/twe_compat.h,v 1.13 2006/02/17 19:18:06 dillon Exp $ 31 */ 32 /* 33 * Portability and compatibility interfaces. 34 */ 35 36 #if defined(__FreeBSD__) || defined(__DragonFly__) 37 /****************************************************************************** 38 * FreeBSD-4 or DragonFly 39 */ 40 #define TWE_SUPPORTED_PLATFORM 41 42 #include <sys/param.h> 43 #include <sys/cons.h> 44 #include <sys/systm.h> 45 #include <sys/malloc.h> 46 #include <sys/kernel.h> 47 #include <sys/sysctl.h> 48 #include <sys/thread2.h> 49 #include <sys/bus.h> 50 #include <sys/conf.h> 51 #include <sys/disk.h> 52 #include <sys/stat.h> 53 54 #include <sys/devicestat.h> 55 56 #include <machine/bus_pio.h> 57 #include <machine/bus.h> 58 #include <machine/resource.h> 59 #include <machine/md_var.h> 60 61 #include <sys/rman.h> 62 63 #include <vm/vm.h> 64 #include <vm/pmap.h> 65 66 #include <bus/pci/pcireg.h> 67 #include <bus/pci/pcivar.h> 68 69 /* 70 * These macros allows us to build a version of the driver which can 71 * safely be loaded into a kernel which already contains a 'twe' driver, 72 * and which will override it in all things. 73 * 74 * All public symbols must be listed here. 75 */ 76 #ifdef TWE_OVERRIDE 77 /* public symbols defined in twe.c */ 78 #define twe_setup Xtwe_setup 79 #define twe_init Xtwe_init 80 #define twe_deinit Xtwe_deinit 81 #define twe_intr Xtwe_intr 82 #define twe_startio Xtwe_startio 83 #define twe_dump_blocks Xtwe_dump_blocks 84 #define twe_ioctl Xtwe_ioctl 85 #define twe_enable_interrupts Xtwe_enable_interrupts 86 #define twe_disable_interrupts Xtwe_disable_interrupts 87 #define twe_describe_controller Xtwe_describe_controller 88 #define twe_describe_code Xtwe_describe_code 89 #define twe_print_controller Xtwe_print_controller 90 91 /* public symbols defined in twe_freebsd.c */ 92 #define twe_attach_drive Xtwe_attach_drive 93 #define twe_clear_pci_parity_error Xtwe_clear_pci_parity_error 94 #define twe_clear_pci_abort Xtwe_clear_pci_abort 95 #define twed_intr Xtwed_intr 96 #define twe_allocate_request Xtwe_allocate_request 97 #define twe_map_request Xtwe_map_request 98 #define twe_unmap_request Xtwe_unmap_request 99 100 /* public symbols defined in twe_tables.h */ 101 #define twe_table_status Xtwe_table_status 102 #define twe_table_unitstate Xtwe_table_unitstate 103 #define twe_table_unittype Xtwe_table_unittype 104 #define twe_table_aen Xtwe_table_aen 105 #define twe_table_opcode Xtwe_table_opcode 106 107 #define TWE_MALLOC_CLASS M_XTWE 108 109 #else /* TWE_OVERRIDE */ 110 111 #define TWE_MALLOC_CLASS M_TWE 112 113 #endif /* TWE_OVERRIDE */ 114 115 /* 116 * Wrappers for bus-space actions 117 */ 118 #define TWE_CONTROL(sc, val) bus_space_write_4(sc->twe_btag, sc->twe_bhandle, 0x0, (u_int32_t)val) 119 #define TWE_STATUS(sc) (u_int32_t)bus_space_read_4(sc->twe_btag, sc->twe_bhandle, 0x4) 120 #define TWE_COMMAND_QUEUE(sc, val) bus_space_write_4(sc->twe_btag, sc->twe_bhandle, 0x8, (u_int32_t)val) 121 #define TWE_RESPONSE_QUEUE(sc) (TWE_Response_Queue)bus_space_read_4(sc->twe_btag, sc->twe_bhandle, 0xc) 122 123 /* 124 * FreeBSD-specific softc elements 125 */ 126 #define TWE_PLATFORM_SOFTC \ 127 device_t twe_dev; /* bus device */ \ 128 dev_t twe_dev_t; /* control device */ \ 129 struct resource *twe_io; /* register interface window */ \ 130 bus_space_handle_t twe_bhandle; /* bus space handle */ \ 131 bus_space_tag_t twe_btag; /* bus space tag */ \ 132 bus_dma_tag_t twe_parent_dmat; /* parent DMA tag */ \ 133 bus_dma_tag_t twe_buffer_dmat; /* data buffer DMA tag */ \ 134 struct resource *twe_irq; /* interrupt */ \ 135 void *twe_intr; /* interrupt handle */ \ 136 struct intr_config_hook twe_ich; /* delayed-startup hook */ \ 137 struct sysctl_ctx_list sysctl_ctx; \ 138 struct sysctl_oid *sysctl_tree; 139 140 /* 141 * FreeBSD-specific request elements 142 */ 143 #define TWE_PLATFORM_REQUEST \ 144 bus_dmamap_t tr_cmdmap; /* DMA map for command */ \ 145 u_int32_t tr_cmdphys; /* address of command in controller space */ \ 146 bus_dmamap_t tr_dmamap; /* DMA map for data */ \ 147 u_int32_t tr_dataphys; /* data buffer base address in controller space */ 148 149 /* 150 * Output identifying the controller/disk 151 */ 152 #define twe_printf(sc, fmt, args...) device_printf(sc->twe_dev, fmt , ##args) 153 #define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args) 154 155 #if defined(__DragonFly__) || __FreeBSD_version < 500003 156 # include <machine/clock.h> 157 158 #ifndef __DragonFly__ 159 # define INTR_ENTROPY 0 160 #endif 161 162 # include <sys/buf.h> /* old buf style */ 163 # include <sys/buf2.h> /* bufq stuff */ 164 #define FREEBSD_4 165 typedef struct bio twe_bio; 166 typedef struct bio_queue_head twe_bioq; 167 #if 0 168 # define TWE_BIO_QINIT(bq) bioq_init(&bq); 169 # define TWE_BIO_QINSERT(bq, bp) bioq_insert_tail(&bq, bp) 170 # define TWE_BIO_QFIRST(bq) bioq_first(&bq) 171 # define TWE_BIO_QREMOVE(bq, bp) bioq_remove(&bq, bp) 172 # define TWE_BIO_IS_READ(bp) ((bp)->b_flags & B_READ) 173 # define TWE_BIO_DATA(bp) (bp)->b_data 174 # define TWE_BIO_LENGTH(bp) (bp)->b_bcount 175 # define TWE_BIO_LBA(bp) (bp)->b_pblkno 176 # define TWE_BIO_SOFTC(bp) (bp)->b_dev->si_drv1 177 # define TWE_BIO_UNIT(bp) ((struct twed_softc *)(TWE_BIO_SOFTC(bp)))->twed_drive->td_twe_unit 178 # define TWE_BIO_SET_ERROR(bp, err) do { (bp)->b_error = err; (bp)->b_flags |= B_ERROR;} while(0) 179 # define TWE_BIO_HAS_ERROR(bp) ((bp)->b_flags & B_ERROR) 180 # define TWE_BIO_RESID(bp) (bp)->b_resid 181 # define TWE_BIO_DONE(bp) biodone(bp) 182 # define TWE_BIO_STATS_START(bp) devstat_start_transaction(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats) 183 # define TWE_BIO_STATS_END(bp) devstat_end_transaction_buf(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats, bp) 184 #endif 185 #else 186 # include <sys/bio.h> 187 typedef struct bio twe_bio; 188 typedef struct bio_queue_head twe_bioq; 189 # define TWE_BIO_QINIT(bq) bioq_init(&bq); 190 # define TWE_BIO_QINSERT(bq, bp) bioq_insert_tail(&bq, bp) 191 # define TWE_BIO_QFIRST(bq) bioq_first(&bq) 192 # define TWE_BIO_QREMOVE(bq, bp) bioq_remove(&bq, bp) 193 # define TWE_BIO_IS_READ(bp) ((bp)->bio_cmd == BIO_READ) 194 # define TWE_BIO_DATA(bp) (bp)->bio_data 195 # define TWE_BIO_LENGTH(bp) (bp)->bio_bcount 196 # define TWE_BIO_LBA(bp) (bp)->bio_pblkno 197 # define TWE_BIO_SOFTC(bp) (bp)->bio_dev->si_drv1 198 # define TWE_BIO_UNIT(bp) ((struct twed_softc *)(TWE_BIO_SOFTC(bp)))->twed_drive->td_twe_unit 199 # define TWE_BIO_SET_ERROR(bp, err) do { (bp)->bio_error = err; (bp)->bio_flags |= BIO_ERROR;} while(0) 200 # define TWE_BIO_HAS_ERROR(bp) ((bp)->bio_flags & BIO_ERROR) 201 # define TWE_BIO_RESID(bp) (bp)->bio_resid 202 # define TWE_BIO_DONE(bp) biodone(bp) 203 # define TWE_BIO_STATS_START(bp) devstat_start_transaction(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats) 204 # define TWE_BIO_STATS_END(bp) devstat_end_transaction_bio(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats, bp) 205 #endif 206 207 #endif /* FreeBSD or DragonFly */ 208 209 #ifndef TWE_SUPPORTED_PLATFORM 210 #error platform not supported 211 #endif 212