1*86d7f5d3SJohn Marino /*- 2*86d7f5d3SJohn Marino * Copyright (c) 2006-2007 Daniel Roethlisberger <daniel@roe.ch> 3*86d7f5d3SJohn Marino * All rights reserved. 4*86d7f5d3SJohn Marino * 5*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 6*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 7*86d7f5d3SJohn Marino * are met: 8*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 9*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 10*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 11*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 12*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 13*86d7f5d3SJohn Marino * 14*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*86d7f5d3SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*86d7f5d3SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*86d7f5d3SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*86d7f5d3SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*86d7f5d3SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*86d7f5d3SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*86d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*86d7f5d3SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*86d7f5d3SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*86d7f5d3SJohn Marino * SUCH DAMAGE. 25*86d7f5d3SJohn Marino * 26*86d7f5d3SJohn Marino * $FreeBSD: src/sys/dev/cmx/cmxvar.h,v 1.1 2008/03/06 08:09:45 rink Exp $ 27*86d7f5d3SJohn Marino * $DragonFly: src/sys/dev/misc/cmx/cmxvar.h,v 1.1 2008/04/23 08:57:10 hasso Exp $ 28*86d7f5d3SJohn Marino */ 29*86d7f5d3SJohn Marino 30*86d7f5d3SJohn Marino /*#define CMX_DEBUG*/ 31*86d7f5d3SJohn Marino /*#define CMX_INTR*/ 32*86d7f5d3SJohn Marino 33*86d7f5d3SJohn Marino #define CMX_MIN_RDLEN 10 /* min read length */ 34*86d7f5d3SJohn Marino #define CMX_MIN_WRLEN 5 /* min write length */ 35*86d7f5d3SJohn Marino #define CMX_BUFSZ 512 /* I/O block size */ 36*86d7f5d3SJohn Marino 37*86d7f5d3SJohn Marino struct cmx_softc { 38*86d7f5d3SJohn Marino device_t dev; /* pccard device */ 39*86d7f5d3SJohn Marino struct cdev *cdev; /* character device */ 40*86d7f5d3SJohn Marino 41*86d7f5d3SJohn Marino struct resource *ioport; /* io port resource descriptor */ 42*86d7f5d3SJohn Marino int ioport_rid; /* io port resource identification */ 43*86d7f5d3SJohn Marino 44*86d7f5d3SJohn Marino bus_space_tag_t bst; /* bus space tag */ 45*86d7f5d3SJohn Marino bus_space_handle_t bsh; /* bus space handle */ 46*86d7f5d3SJohn Marino 47*86d7f5d3SJohn Marino #ifdef CMX_INTR 48*86d7f5d3SJohn Marino struct resource* irq; /* irq resource descriptor */ 49*86d7f5d3SJohn Marino int irq_rid; /* irq resource identification */ 50*86d7f5d3SJohn Marino void *ih; /* intr handle */ 51*86d7f5d3SJohn Marino #endif 52*86d7f5d3SJohn Marino 53*86d7f5d3SJohn Marino struct lock mtx; /* per-unit lock */ 54*86d7f5d3SJohn Marino struct callout ch; /* callout handle */ 55*86d7f5d3SJohn Marino struct kqinfo kq; /* select/poll/kq queue handle */ 56*86d7f5d3SJohn Marino 57*86d7f5d3SJohn Marino int open; /* is chardev open? */ 58*86d7f5d3SJohn Marino int polling; /* are we polling? */ 59*86d7f5d3SJohn Marino int dying; /* are we detaching? */ 60*86d7f5d3SJohn Marino 61*86d7f5d3SJohn Marino unsigned long timeout; /* response timeout */ 62*86d7f5d3SJohn Marino 63*86d7f5d3SJohn Marino uint8_t buf[CMX_BUFSZ]; /* read/write buffer */ 64*86d7f5d3SJohn Marino }; 65*86d7f5d3SJohn Marino 66*86d7f5d3SJohn Marino extern devclass_t cmx_devclass; 67*86d7f5d3SJohn Marino 68*86d7f5d3SJohn Marino void cmx_init_softc(device_t); 69*86d7f5d3SJohn Marino int cmx_alloc_resources(device_t); 70*86d7f5d3SJohn Marino void cmx_release_resources(device_t); 71*86d7f5d3SJohn Marino int cmx_attach(device_t); 72*86d7f5d3SJohn Marino int cmx_detach(device_t); 73*86d7f5d3SJohn Marino 74*86d7f5d3SJohn Marino #define CMX_READ_1(sc, off) \ 75*86d7f5d3SJohn Marino (bus_space_read_1((sc)->bst, (sc)->bsh, off)) 76*86d7f5d3SJohn Marino #define CMX_WRITE_1(sc, off, val) \ 77*86d7f5d3SJohn Marino (bus_space_write_1((sc)->bst, (sc)->bsh, off, val)) 78*86d7f5d3SJohn Marino 79*86d7f5d3SJohn Marino #define cmx_read_BSR(sc) \ 80*86d7f5d3SJohn Marino CMX_READ_1(sc, REG_OFFSET_BSR) 81*86d7f5d3SJohn Marino #define cmx_write_BSR(sc, val) \ 82*86d7f5d3SJohn Marino CMX_WRITE_1(sc, REG_OFFSET_BSR, val) 83*86d7f5d3SJohn Marino #define cmx_read_SCR(sc) \ 84*86d7f5d3SJohn Marino CMX_READ_1(sc, REG_OFFSET_SCR) 85*86d7f5d3SJohn Marino #define cmx_write_SCR(sc, val) \ 86*86d7f5d3SJohn Marino CMX_WRITE_1(sc, REG_OFFSET_SCR, val) 87*86d7f5d3SJohn Marino #define cmx_read_DTR(sc) \ 88*86d7f5d3SJohn Marino CMX_READ_1(sc, REG_OFFSET_DTR) 89*86d7f5d3SJohn Marino #define cmx_write_DTR(sc, val) \ 90*86d7f5d3SJohn Marino CMX_WRITE_1(sc, REG_OFFSET_DTR, val) 91*86d7f5d3SJohn Marino 92*86d7f5d3SJohn Marino #define cmx_test(byte, flags, test) \ 93*86d7f5d3SJohn Marino (((byte) & (flags)) == ((test) ? (flags) : 0)) 94*86d7f5d3SJohn Marino 95*86d7f5d3SJohn Marino #define cmx_test_BSR(sc, flags, test) \ 96*86d7f5d3SJohn Marino cmx_test(cmx_read_BSR(sc), flags, test) 97*86d7f5d3SJohn Marino 98*86d7f5d3SJohn Marino #define CMX_LOCK(sc) lockmgr(&(sc)->mtx, LK_EXCLUSIVE); 99*86d7f5d3SJohn Marino #define CMX_UNLOCK(sc) lockmgr(&(sc)->mtx, LK_RELEASE); 100*86d7f5d3SJohn Marino #define CMX_LOCK_ASSERT(sc, what) 101