2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2000 Michael Smith
5 * Copyright (c) 2003 Paul Saab
6 * Copyright (c) 2003 Vinod Kashyap
7 * Copyright (c) 2000 BSDi
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Portability and compatibility interfaces.
38 /******************************************************************************
41 #define TWE_SUPPORTED_PLATFORM
43 #include <sys/param.h>
44 #include <sys/endian.h>
45 #include <sys/systm.h>
46 #include <sys/malloc.h>
47 #include <sys/kernel.h>
49 #include <sys/module.h>
50 #include <sys/mutex.h>
51 #include <sys/sysctl.h>
60 #include <machine/bus.h>
61 #include <machine/resource.h>
64 #include <dev/pci/pcireg.h>
65 #include <dev/pci/pcivar.h>
67 #include <geom/geom_disk.h>
69 #define TWE_DRIVER_NAME twe
70 #define TWED_DRIVER_NAME twed
71 #define TWE_MALLOC_CLASS M_TWE
74 * Wrappers for bus-space actions
76 #define TWE_CONTROL(sc, val) bus_write_4((sc)->twe_io, 0x0, (u_int32_t)val)
77 #define TWE_STATUS(sc) (u_int32_t)bus_read_4((sc)->twe_io, 0x4)
78 #define TWE_COMMAND_QUEUE(sc, val) bus_write_4((sc)->twe_io, 0x8, (u_int32_t)val)
79 #define TWE_RESPONSE_QUEUE(sc) (TWE_Response_Queue)bus_read_4((sc)->twe_io, 0xc)
82 * FreeBSD-specific softc elements
84 #define TWE_PLATFORM_SOFTC \
85 bus_dmamap_t twe_cmdmap; /* DMA map for command */ \
86 u_int32_t twe_cmdphys; /* address of command in controller space */ \
87 device_t twe_dev; /* bus device */ \
88 struct cdev *twe_dev_t; /* control device */ \
89 struct resource *twe_io; /* register interface window */ \
90 bus_dma_tag_t twe_parent_dmat; /* parent DMA tag */ \
91 bus_dma_tag_t twe_buffer_dmat; /* data buffer DMA tag */ \
92 bus_dma_tag_t twe_cmd_dmat; /* command buffer DMA tag */ \
93 bus_dma_tag_t twe_immediate_dmat; /* command buffer DMA tag */ \
94 struct resource *twe_irq; /* interrupt */ \
95 void *twe_intr; /* interrupt handle */ \
96 struct intr_config_hook twe_ich; /* delayed-startup hook */ \
97 void *twe_cmd; /* command structures */ \
98 void *twe_immediate; /* immediate commands */ \
99 bus_dmamap_t twe_immediate_map; \
100 struct mtx twe_io_lock; \
101 struct sx twe_config_lock;
104 * FreeBSD-specific request elements
106 #define TWE_PLATFORM_REQUEST \
107 bus_dmamap_t tr_dmamap; /* DMA map for data */ \
108 u_int32_t tr_dataphys; /* data buffer base address in controller space */
111 * Output identifying the controller/disk
113 #define twe_printf(sc, fmt, args...) device_printf(sc->twe_dev, fmt , ##args)
114 #define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args)
116 #define TWE_IO_LOCK(sc) mtx_lock(&(sc)->twe_io_lock)
117 #define TWE_IO_UNLOCK(sc) mtx_unlock(&(sc)->twe_io_lock)
118 #define TWE_IO_ASSERT_LOCKED(sc) mtx_assert(&(sc)->twe_io_lock, MA_OWNED)
119 #define TWE_CONFIG_LOCK(sc) sx_xlock(&(sc)->twe_config_lock)
120 #define TWE_CONFIG_UNLOCK(sc) sx_xunlock(&(sc)->twe_config_lock)
121 #define TWE_CONFIG_ASSERT_LOCKED(sc) sx_assert(&(sc)->twe_config_lock, SA_XLOCKED)
125 #ifndef TWE_SUPPORTED_PLATFORM
126 #error platform not supported