2000-10-25 06:59:06 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2000-10-25 06:59:06 +00:00
|
|
|
* Copyright (c) 2000 Michael Smith
|
2003-12-02 07:57:20 +00:00
|
|
|
* Copyright (c) 2003 Paul Saab
|
|
|
|
* Copyright (c) 2003 Vinod Kashyap
|
2000-10-25 06:59:06 +00:00
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Portability and compatibility interfaces.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
/******************************************************************************
|
|
|
|
* FreeBSD
|
|
|
|
*/
|
|
|
|
#define TWE_SUPPORTED_PLATFORM
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2003-08-12 06:38:55 +00:00
|
|
|
#include <sys/endian.h>
|
2000-10-25 06:59:06 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2012-08-13 21:29:34 +00:00
|
|
|
#include <sys/lock.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2012-08-13 21:29:34 +00:00
|
|
|
#include <sys/mutex.h>
|
2003-08-05 19:55:21 +00:00
|
|
|
#include <sys/sysctl.h>
|
2012-08-13 21:29:34 +00:00
|
|
|
#include <sys/sx.h>
|
2000-10-25 06:59:06 +00:00
|
|
|
|
2012-09-07 18:41:19 +00:00
|
|
|
#include <sys/bio.h>
|
2000-10-25 06:59:06 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2003-08-22 07:08:17 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2000-10-25 06:59:06 +00:00
|
|
|
|
2012-09-07 18:41:19 +00:00
|
|
|
#include <geom/geom_disk.h>
|
|
|
|
|
2000-10-25 06:59:06 +00:00
|
|
|
#define TWE_DRIVER_NAME twe
|
|
|
|
#define TWED_DRIVER_NAME twed
|
|
|
|
#define TWE_MALLOC_CLASS M_TWE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrappers for bus-space actions
|
|
|
|
*/
|
2012-08-13 21:29:34 +00:00
|
|
|
#define TWE_CONTROL(sc, val) bus_write_4((sc)->twe_io, 0x0, (u_int32_t)val)
|
|
|
|
#define TWE_STATUS(sc) (u_int32_t)bus_read_4((sc)->twe_io, 0x4)
|
|
|
|
#define TWE_COMMAND_QUEUE(sc, val) bus_write_4((sc)->twe_io, 0x8, (u_int32_t)val)
|
|
|
|
#define TWE_RESPONSE_QUEUE(sc) (TWE_Response_Queue)bus_read_4((sc)->twe_io, 0xc)
|
2000-10-25 06:59:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD-specific softc elements
|
|
|
|
*/
|
|
|
|
#define TWE_PLATFORM_SOFTC \
|
2003-08-12 06:38:55 +00:00
|
|
|
bus_dmamap_t twe_cmdmap; /* DMA map for command */ \
|
|
|
|
u_int32_t twe_cmdphys; /* address of command in controller space */ \
|
2000-10-25 06:59:06 +00:00
|
|
|
device_t twe_dev; /* bus device */ \
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *twe_dev_t; /* control device */ \
|
2000-10-25 06:59:06 +00:00
|
|
|
struct resource *twe_io; /* register interface window */ \
|
|
|
|
bus_dma_tag_t twe_parent_dmat; /* parent DMA tag */ \
|
|
|
|
bus_dma_tag_t twe_buffer_dmat; /* data buffer DMA tag */ \
|
2003-08-12 06:38:55 +00:00
|
|
|
bus_dma_tag_t twe_cmd_dmat; /* command buffer DMA tag */ \
|
|
|
|
bus_dma_tag_t twe_immediate_dmat; /* command buffer DMA tag */ \
|
2000-10-25 06:59:06 +00:00
|
|
|
struct resource *twe_irq; /* interrupt */ \
|
|
|
|
void *twe_intr; /* interrupt handle */ \
|
2003-08-05 19:55:21 +00:00
|
|
|
struct intr_config_hook twe_ich; /* delayed-startup hook */ \
|
2003-08-12 06:38:55 +00:00
|
|
|
void *twe_cmd; /* command structures */ \
|
|
|
|
void *twe_immediate; /* immediate commands */ \
|
|
|
|
bus_dmamap_t twe_immediate_map; \
|
2012-08-13 21:29:34 +00:00
|
|
|
struct mtx twe_io_lock; \
|
|
|
|
struct sx twe_config_lock;
|
2000-10-25 06:59:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FreeBSD-specific request elements
|
|
|
|
*/
|
|
|
|
#define TWE_PLATFORM_REQUEST \
|
|
|
|
bus_dmamap_t tr_dmamap; /* DMA map for data */ \
|
|
|
|
u_int32_t tr_dataphys; /* data buffer base address in controller space */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output identifying the controller/disk
|
|
|
|
*/
|
|
|
|
#define twe_printf(sc, fmt, args...) device_printf(sc->twe_dev, fmt , ##args)
|
|
|
|
#define twed_printf(twed, fmt, args...) device_printf(twed->twed_dev, fmt , ##args)
|
|
|
|
|
2012-08-13 21:29:34 +00:00
|
|
|
#define TWE_IO_LOCK(sc) mtx_lock(&(sc)->twe_io_lock)
|
|
|
|
#define TWE_IO_UNLOCK(sc) mtx_unlock(&(sc)->twe_io_lock)
|
|
|
|
#define TWE_IO_ASSERT_LOCKED(sc) mtx_assert(&(sc)->twe_io_lock, MA_OWNED)
|
|
|
|
#define TWE_CONFIG_LOCK(sc) sx_xlock(&(sc)->twe_config_lock)
|
|
|
|
#define TWE_CONFIG_UNLOCK(sc) sx_xunlock(&(sc)->twe_config_lock)
|
|
|
|
#define TWE_CONFIG_ASSERT_LOCKED(sc) sx_assert(&(sc)->twe_config_lock, SA_XLOCKED)
|
2000-10-25 06:59:06 +00:00
|
|
|
|
|
|
|
#endif /* FreeBSD */
|
|
|
|
|
|
|
|
#ifndef TWE_SUPPORTED_PLATFORM
|
|
|
|
#error platform not supported
|
|
|
|
#endif
|