1 /* $NetBSD: wdvar.h,v 1.9 2010/01/10 16:20:45 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 uint8_t *c_cmdbase; 53 volatile uint8_t *c_ctlbase; 54 volatile uint8_t *c_cmdreg[WDC_NPORTS + WDC_NSHADOWREG]; 55 volatile uint16_t *c_data; 56 57 uint8_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 uint16_t sc_flags; 70 71 u_int sc_part; 72 u_int sc_unit; 73 74 uint64_t sc_capacity; 75 uint32_t sc_capacity28; 76 77 struct ataparams sc_params; 78 struct disklabel sc_label; 79 struct wdc_channel sc_channel; 80 }; 81 82 struct wdc_command { 83 uint8_t drive; /* drive id */ 84 85 uint8_t r_command; /* Parameters to upload to registers */ 86 uint8_t r_head; 87 uint16_t r_cyl; 88 uint8_t r_sector; 89 uint8_t r_count; 90 uint8_t r_features; 91 92 uint16_t bcount; 93 void *data; 94 95 uint64_t r_blkno; 96 }; 97 98 int wdc_init(struct wd_softc *, u_int *); 99 int wdccommand(struct wd_softc *, struct wdc_command *); 100 int wdccommandext(struct wd_softc *, struct wdc_command *); 101 int wdc_exec_read(struct wd_softc *, uint8_t, daddr_t, void *); 102 int wdc_exec_identify(struct wd_softc *, void *); 103 104 int pciide_init(struct wdc_channel *, u_int *); 105 106 #endif /* _STAND_WDVAR_H */ 107