1 /* $NetBSD: wdvar.h,v 1.5 2004/09/01 15:54:39 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 5 * Copyright (c) 2001 Dynarc AB, Sweden. All rights reserved. 6 * 7 * This code is derived from software written by Anders Magnusson, 8 * ragge@ludd.luth.se 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 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. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef _STAND_WDVAR_H 34 #define _STAND_WDVAR_H 35 36 #include <dev/ic/wdcreg.h> 37 #include <dev/ata/atareg.h> 38 #include <dev/pci/pciidereg.h> 39 40 #include <mips/cpuregs.h> 41 42 #include <sys/disklabel.h> 43 #include <sys/bootblock.h> 44 45 #define WDC_TIMEOUT 2000000 46 #define PCIIDE_CHANNEL_NDEV 2 47 #define NUNITS (PCIIDE_CHANNEL_NDEV * PCIIDE_NUM_CHANNELS) 48 #define WDC_NPORTS 8 /* XXX */ 49 #define WDC_NSHADOWREG 2 /* XXX */ 50 51 struct wdc_channel { 52 volatile u_int8_t *c_cmdbase; 53 volatile u_int8_t *c_ctlbase; 54 volatile u_int8_t *c_cmdreg[WDC_NPORTS + WDC_NSHADOWREG]; 55 volatile u_int16_t *c_data; 56 57 u_int8_t compatchan; 58 }; 59 60 #define WDC_READ_REG(chp, reg) *(chp)->c_cmdreg[(reg)] 61 #define WDC_WRITE_REG(chp, reg, val) *(chp)->c_cmdreg[(reg)] = (val) 62 #define WDC_READ_CTLREG(chp, reg) (chp)->c_ctlbase[(reg)] 63 #define WDC_WRITE_CTLREG(chp, reg, val) (chp)->c_ctlbase[(reg)] = (val) 64 #define WDC_READ_DATA(chp) *(chp)->c_data 65 66 struct wd_softc { 67 #define WDF_LBA 0x0001 68 #define WDF_LBA48 0x0002 69 u_int16_t sc_flags; 70 71 u_int sc_part; 72 u_int sc_unit; 73 74 u_int64_t sc_capacity; 75 76 struct ataparams sc_params; 77 struct disklabel sc_label; 78 struct wdc_channel sc_channel; 79 }; 80 81 struct wdc_command { 82 u_int8_t drive; /* drive id */ 83 84 u_int8_t r_command; /* Parameters to upload to registers */ 85 u_int8_t r_head; 86 u_int16_t r_cyl; 87 u_int8_t r_sector; 88 u_int8_t r_count; 89 u_int8_t r_precomp; 90 91 u_int16_t bcount; 92 void *data; 93 94 u_int64_t r_blkno; 95 }; 96 97 int wdc_init (struct wd_softc*, u_int*); 98 int wdccommand (struct wd_softc*, struct wdc_command*); 99 int wdccommandext (struct wd_softc*, struct wdc_command*); 100 int wdc_exec_read (struct wd_softc*, u_int8_t, daddr_t, void*); 101 int wdc_exec_identify (struct wd_softc*, void*); 102 103 int pciide_init (struct wdc_channel*, u_int*); 104 105 #endif /* _STAND_WDVAR_H */ 106