1a6e4d8c4SNate Lawson /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4f86e6000SWarner Losh * Copyright (c) 2004-2005 M. Warner Losh <imp@FreeBSD.org> 56d6fa4fdSWarner Losh * 66d6fa4fdSWarner Losh * Redistribution and use in source and binary forms, with or without 76d6fa4fdSWarner Losh * modification, are permitted provided that the following conditions 86d6fa4fdSWarner Losh * are met: 96d6fa4fdSWarner Losh * 1. Redistributions of source code must retain the above copyright 10ac673f9aSWarner Losh * notice, this list of conditions and the following disclaimer. 116d6fa4fdSWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 12ac673f9aSWarner Losh * notice, this list of conditions and the following disclaimer in the 13ac673f9aSWarner Losh * documentation and/or other materials provided with the distribution. 146d6fa4fdSWarner Losh * 156d6fa4fdSWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 166d6fa4fdSWarner Losh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 176d6fa4fdSWarner Losh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18ac673f9aSWarner Losh * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19ac673f9aSWarner Losh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 206d6fa4fdSWarner Losh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 216d6fa4fdSWarner Losh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 226d6fa4fdSWarner Losh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 236d6fa4fdSWarner Losh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 246d6fa4fdSWarner Losh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 256d6fa4fdSWarner Losh * SUCH DAMAGE. 266d6fa4fdSWarner Losh */ 276d6fa4fdSWarner Losh 286d6fa4fdSWarner Losh /* XXX should audit this file to see if additional copyrights needed */ 296d6fa4fdSWarner Losh 301b67be7bSPoul-Henning Kamp enum fdc_type { 316d6fa4fdSWarner Losh FDC_NE765, FDC_ENHANCED, FDC_UNKNOWN = -1 326d6fa4fdSWarner Losh }; 336d6fa4fdSWarner Losh 346d6fa4fdSWarner Losh /* 356d6fa4fdSWarner Losh * Per controller structure (softc). 366d6fa4fdSWarner Losh */ 371b67be7bSPoul-Henning Kamp struct fdc_data { 386d6fa4fdSWarner Losh int fdcu; /* our unit number */ 396d6fa4fdSWarner Losh int dmachan; 406d6fa4fdSWarner Losh int flags; 411b67be7bSPoul-Henning Kamp #define FDC_HASDMA 0x01 426d6fa4fdSWarner Losh #define FDC_STAT_VALID 0x08 436d6fa4fdSWarner Losh #define FDC_HAS_FIFO 0x10 446d6fa4fdSWarner Losh #define FDC_NEEDS_RESET 0x20 45973bfe6cSWarner Losh #define FDC_NODMA 0x40 /* Don't do DMA */ 46973bfe6cSWarner Losh #define FDC_NOFAST 0x80 /* Don't register isr as a fast one */ 4702910eeeSJoerg Wunsch #define FDC_KTHREAD_EXIT 0x1000 /* request worker thread to stop */ 4802910eeeSJoerg Wunsch #define FDC_KTHREAD_ALIVE 0x2000 /* worker thread is alive */ 491b67be7bSPoul-Henning Kamp struct fd_data *fd; /* The active drive */ 506d6fa4fdSWarner Losh int retry; 516d6fa4fdSWarner Losh int fdout; /* mirror of the w/o digital output reg */ 526d6fa4fdSWarner Losh u_int status[7]; /* copy of the registers */ 536d6fa4fdSWarner Losh enum fdc_type fdct; /* chip version of FDC */ 546d6fa4fdSWarner Losh int fdc_errs; /* number of logged errors */ 556d6fa4fdSWarner Losh struct bio_queue_head head; 566d6fa4fdSWarner Losh struct bio *bp; /* active buffer */ 57973bfe6cSWarner Losh struct resource *res_irq, *res_drq; 58973bfe6cSWarner Losh int rid_irq, rid_drq; 59973bfe6cSWarner Losh #define FDC_MAXREG 8 60973bfe6cSWarner Losh int ridio[FDC_MAXREG]; 61973bfe6cSWarner Losh struct resource *resio[FDC_MAXREG]; 62973bfe6cSWarner Losh bus_space_tag_t iot; 63973bfe6cSWarner Losh bus_space_handle_t ioh[FDC_MAXREG]; 64973bfe6cSWarner Losh int ioff[FDC_MAXREG]; 656d6fa4fdSWarner Losh void *fdc_intr; 66cde57cacSAdrian Chadd device_t fdc_dev; 671b67be7bSPoul-Henning Kamp struct mtx fdc_mtx; 681b67be7bSPoul-Henning Kamp struct proc *fdc_thread; 696d6fa4fdSWarner Losh }; 706d6fa4fdSWarner Losh 71752d4735SNate Lawson enum fdc_device_ivars { 72752d4735SNate Lawson FDC_IVAR_FDUNIT, 73752d4735SNate Lawson FDC_IVAR_FDTYPE, 74752d4735SNate Lawson }; 75752d4735SNate Lawson 76752d4735SNate Lawson __BUS_ACCESSOR(fdc, fdunit, FDC, FDUNIT, int); 77752d4735SNate Lawson __BUS_ACCESSOR(fdc, fdtype, FDC, FDTYPE, int); 78752d4735SNate Lawson 796d6fa4fdSWarner Losh void fdc_release_resources(struct fdc_data *); 806d6fa4fdSWarner Losh int fdc_attach(device_t); 81fed2c48aSJohn Baldwin void fdc_start_worker(device_t); 82a6e4d8c4SNate Lawson int fdc_hints_probe(device_t); 836d6fa4fdSWarner Losh int fdc_detach(device_t dev); 84a6e4d8c4SNate Lawson device_t fdc_add_child(device_t, const char *, int); 851b67be7bSPoul-Henning Kamp int fdc_initial_reset(device_t, struct fdc_data *); 866d6fa4fdSWarner Losh int fdc_print_child(device_t, device_t); 876d6fa4fdSWarner Losh int fdc_read_ivar(device_t, device_t, int, uintptr_t *); 88752d4735SNate Lawson int fdc_write_ivar(device_t, device_t, int, uintptr_t); 89a6e4d8c4SNate Lawson int fdc_isa_alloc_resources(device_t, struct fdc_data *); 90