twe_compat.h revision 146734
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: head/sys/dev/twe/twe_compat.h 146734 2005-05-29 04:42:30Z nyan $
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/module.h>
47#include <sys/sysctl.h>
48
49#include <sys/bus.h>
50#include <sys/conf.h>
51#include <sys/disk.h>
52#include <sys/stat.h>
53
54#include <machine/bus.h>
55#include <machine/resource.h>
56#include <sys/rman.h>
57
58#include <dev/pci/pcireg.h>
59#include <dev/pci/pcivar.h>
60
61#define TWE_DRIVER_NAME		twe
62#define TWED_DRIVER_NAME	twed
63#define TWE_MALLOC_CLASS	M_TWE
64
65/*
66 * Wrappers for bus-space actions
67 */
68#define TWE_CONTROL(sc, val)		bus_space_write_4((sc)->twe_btag, (sc)->twe_bhandle, 0x0, (u_int32_t)val)
69#define TWE_STATUS(sc)			(u_int32_t)bus_space_read_4((sc)->twe_btag, (sc)->twe_bhandle, 0x4)
70#define TWE_COMMAND_QUEUE(sc, val)	bus_space_write_4((sc)->twe_btag, (sc)->twe_bhandle, 0x8, (u_int32_t)val)
71#define TWE_RESPONSE_QUEUE(sc)		(TWE_Response_Queue)bus_space_read_4((sc)->twe_btag, (sc)->twe_bhandle, 0xc)
72
73/*
74 * FreeBSD-specific softc elements
75 */
76#define TWE_PLATFORM_SOFTC								\
77    bus_dmamap_t		twe_cmdmap;	/* DMA map for command */				\
78    u_int32_t			twe_cmdphys;	/* address of command in controller space */		\
79    device_t			twe_dev;		/* bus device */		\
80    struct cdev *twe_dev_t;		/* control device */		\
81    struct resource		*twe_io;		/* register interface window */	\
82    bus_space_handle_t		twe_bhandle;		/* bus space handle */		\
83    bus_space_tag_t		twe_btag;		/* bus space tag */		\
84    bus_dma_tag_t		twe_parent_dmat;	/* parent DMA tag */		\
85    bus_dma_tag_t		twe_buffer_dmat;	/* data buffer DMA tag */	\
86    bus_dma_tag_t		twe_cmd_dmat;		/* command buffer DMA tag */	\
87    bus_dma_tag_t		twe_immediate_dmat;	/* command buffer DMA tag */	\
88    struct resource		*twe_irq;		/* interrupt */			\
89    void			*twe_intr;		/* interrupt handle */		\
90    struct intr_config_hook	twe_ich;		/* delayed-startup hook */	\
91    void			*twe_cmd;		/* command structures */	\
92    void			*twe_immediate;		/* immediate commands */	\
93    bus_dmamap_t		twe_immediate_map;					\
94    struct sysctl_ctx_list	sysctl_ctx;						\
95    struct sysctl_oid		*sysctl_tree;
96
97/*
98 * FreeBSD-specific request elements
99 */
100#define TWE_PLATFORM_REQUEST										\
101    bus_dmamap_t		tr_dmamap;	/* DMA map for data */					\
102    u_int32_t			tr_dataphys;	/* data buffer base address in controller space */
103
104/*
105 * Output identifying the controller/disk
106 */
107#define twe_printf(sc, fmt, args...)	device_printf(sc->twe_dev, fmt , ##args)
108#define twed_printf(twed, fmt, args...)	device_printf(twed->twed_dev, fmt , ##args)
109
110#if __FreeBSD_version < 500003
111# include <machine/clock.h>
112# define INTR_ENTROPY			0
113# define FREEBSD_4
114
115# include <sys/buf.h>			/* old buf style */
116typedef struct buf			twe_bio;
117typedef struct buf_queue_head		twe_bioq;
118# define TWE_BIO_QINIT(bq)		bufq_init(&bq);
119# define TWE_BIO_QINSERT(bq, bp)	bufq_insert_tail(&bq, bp)
120# define TWE_BIO_QFIRST(bq)		bufq_first(&bq)
121# define TWE_BIO_QREMOVE(bq, bp)	bufq_remove(&bq, bp)
122# define TWE_BIO_IS_READ(bp)		((bp)->b_flags & B_READ)
123# define TWE_BIO_DATA(bp)		(bp)->b_data
124# define TWE_BIO_LENGTH(bp)		(bp)->b_bcount
125# define TWE_BIO_LBA(bp)		(bp)->b_pblkno
126# define TWE_BIO_SOFTC(bp)		(bp)->b_dev->si_drv1
127# define TWE_BIO_UNIT(bp)		*(int *)((bp)->b_dev->si_drv2)
128# define TWE_BIO_SET_ERROR(bp, err)	do { (bp)->b_error = err; (bp)->b_flags |= B_ERROR;} while(0)
129# define TWE_BIO_HAS_ERROR(bp)		((bp)->b_flags & B_ERROR)
130# define TWE_BIO_RESID(bp)		(bp)->b_resid
131# define TWE_BIO_DONE(bp)		biodone(bp)
132# define TWE_BIO_STATS_START(bp)	devstat_start_transaction(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats)
133# define TWE_BIO_STATS_END(bp)		devstat_end_transaction_buf(&((struct twed_softc *)TWE_BIO_SOFTC(bp))->twed_stats, bp)
134#else
135# include <sys/bio.h>
136# include <geom/geom_disk.h>
137typedef struct bio			twe_bio;
138typedef struct bio_queue_head		twe_bioq;
139# define TWE_BIO_QINIT(bq)		bioq_init(&bq);
140# define TWE_BIO_QINSERT(bq, bp)	bioq_insert_tail(&bq, bp)
141# define TWE_BIO_QFIRST(bq)		bioq_first(&bq)
142# define TWE_BIO_QREMOVE(bq, bp)	bioq_remove(&bq, bp)
143# define TWE_BIO_IS_READ(bp)		((bp)->bio_cmd == BIO_READ)
144# define TWE_BIO_DATA(bp)		(bp)->bio_data
145# define TWE_BIO_LENGTH(bp)		(bp)->bio_bcount
146# define TWE_BIO_LBA(bp)		(bp)->bio_pblkno
147# define TWE_BIO_SOFTC(bp)		(bp)->bio_disk->d_drv1
148# define TWE_BIO_UNIT(bp)		*(int *)(bp->bio_driver1)
149# define TWE_BIO_SET_ERROR(bp, err)	do { (bp)->bio_error = err; (bp)->bio_flags |= BIO_ERROR;} while(0)
150# define TWE_BIO_HAS_ERROR(bp)		((bp)->bio_flags & BIO_ERROR)
151# define TWE_BIO_RESID(bp)		(bp)->bio_resid
152# define TWE_BIO_DONE(bp)		biodone(bp)
153# define TWE_BIO_STATS_START(bp)
154# define TWE_BIO_STATS_END(bp)
155#endif
156
157#endif /* FreeBSD */
158
159#ifndef TWE_SUPPORTED_PLATFORM
160#error platform not supported
161#endif
162