Home | History | Annotate | Line # | Download | only in boot
wdvar.h revision 1.1
      1  1.1  kiyohara /*	$NetBSD: wdvar.h,v 1.1 2011/03/03 05:59:37 kiyohara Exp $	*/
      2  1.1  kiyohara 
      3  1.1  kiyohara /*-
      4  1.1  kiyohara  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  1.1  kiyohara  * Copyright (c) 2001 Dynarc AB, Sweden. All rights reserved.
      6  1.1  kiyohara  *
      7  1.1  kiyohara  * This code is derived from software written by Anders Magnusson,
      8  1.1  kiyohara  * ragge (at) ludd.luth.se
      9  1.1  kiyohara  *
     10  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     11  1.1  kiyohara  * modification, are permitted provided that the following conditions
     12  1.1  kiyohara  * are met:
     13  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     14  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     15  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     18  1.1  kiyohara  * 3. The name of the author may not be used to endorse or promote products
     19  1.1  kiyohara  *    derived from this software without specific prior written permission
     20  1.1  kiyohara  *
     21  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  kiyohara  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  kiyohara  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  kiyohara  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  kiyohara  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  kiyohara  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  kiyohara  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  kiyohara  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  kiyohara  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  kiyohara  */
     32  1.1  kiyohara 
     33  1.1  kiyohara #ifndef _STAND_WDVAR_H
     34  1.1  kiyohara #define _STAND_WDVAR_H
     35  1.1  kiyohara 
     36  1.1  kiyohara #include <dev/ic/wdcreg.h>
     37  1.1  kiyohara #include <dev/ata/atareg.h>
     38  1.1  kiyohara #include <dev/pci/pciidereg.h>
     39  1.1  kiyohara 
     40  1.1  kiyohara #include <sys/disklabel.h>
     41  1.1  kiyohara #include <sys/bootblock.h>
     42  1.1  kiyohara 
     43  1.1  kiyohara #define WDC_TIMEOUT		2000000
     44  1.1  kiyohara #define PCIIDE_CHANNEL_NDEV	2
     45  1.1  kiyohara #define NUNITS			(PCIIDE_CHANNEL_NDEV * PCIIDE_NUM_CHANNELS)
     46  1.1  kiyohara #define WDC_NPORTS		8	/* XXX */
     47  1.1  kiyohara #define WDC_NSHADOWREG		2	/* XXX */
     48  1.1  kiyohara 
     49  1.1  kiyohara struct wdc_channel {
     50  1.1  kiyohara 	volatile uint8_t *c_cmdbase;
     51  1.1  kiyohara 	volatile uint8_t *c_ctlbase;
     52  1.1  kiyohara 	volatile uint8_t *c_cmdreg[WDC_NPORTS + WDC_NSHADOWREG];
     53  1.1  kiyohara 	volatile uint16_t *c_data;
     54  1.1  kiyohara 
     55  1.1  kiyohara 	uint8_t compatchan;
     56  1.1  kiyohara };
     57  1.1  kiyohara 
     58  1.1  kiyohara #if defined(SH3)
     59  1.1  kiyohara 
     60  1.1  kiyohara #define WDC_READ_REG(chp, reg)		*(chp)->c_cmdreg[(reg)]
     61  1.1  kiyohara #define WDC_WRITE_REG(chp, reg, val)	*(chp)->c_cmdreg[(reg)] = (val)
     62  1.1  kiyohara #define WDC_READ_CTLREG(chp, reg)	(chp)->c_ctlbase[(reg)]
     63  1.1  kiyohara #define WDC_WRITE_CTLREG(chp, reg, val)	(chp)->c_ctlbase[(reg)] = (val)
     64  1.1  kiyohara #define WDC_READ_DATA(chp)		*(chp)->c_data
     65  1.1  kiyohara #define WDC_READ_DATA_STREAM(chp)	*(chp)->c_data
     66  1.1  kiyohara 
     67  1.1  kiyohara #elif defined(SH4)
     68  1.1  kiyohara 
     69  1.1  kiyohara #include <sh3/devreg.h>
     70  1.1  kiyohara #include <sh3/mmu_sh4.h>
     71  1.1  kiyohara #include <sh3/pte.h>
     72  1.1  kiyohara 
     73  1.1  kiyohara #define WDC_READ_REG(chp, reg) ({					\
     74  1.1  kiyohara 	_reg_write_4(SH4_PTEA, _PG_PCMCIA_IO16 >> _PG_PCMCIA_SHIFT);	\
     75  1.1  kiyohara 	*(chp)->c_cmdreg[(reg)];					\
     76  1.1  kiyohara })
     77  1.1  kiyohara #define WDC_WRITE_REG(chp, reg, val) do {				\
     78  1.1  kiyohara 	_reg_write_4(SH4_PTEA, _PG_PCMCIA_IO16 >> _PG_PCMCIA_SHIFT);	\
     79  1.1  kiyohara 	*(chp)->c_cmdreg[(reg)] = (val);				\
     80  1.1  kiyohara } while (0)
     81  1.1  kiyohara #define WDC_READ_CTLREG(chp, reg) ({					\
     82  1.1  kiyohara 	_reg_write_4(SH4_PTEA, _PG_PCMCIA_IO16 >> _PG_PCMCIA_SHIFT);	\
     83  1.1  kiyohara 	(chp)->c_ctlbase[(reg)];					\
     84  1.1  kiyohara })
     85  1.1  kiyohara #define WDC_WRITE_CTLREG(chp, reg, val) do {				\
     86  1.1  kiyohara 	_reg_write_4(SH4_PTEA, _PG_PCMCIA_IO16 >> _PG_PCMCIA_SHIFT);	\
     87  1.1  kiyohara 	(chp)->c_ctlbase[(reg)] = (val);				\
     88  1.1  kiyohara } while (0)
     89  1.1  kiyohara #define WDC_READ_DATA(chp) ({						\
     90  1.1  kiyohara 	_reg_write_4(SH4_PTEA, _PG_PCMCIA_IO16 >> _PG_PCMCIA_SHIFT);	\
     91  1.1  kiyohara 	bswap16(*(chp)->c_data);					\
     92  1.1  kiyohara })
     93  1.1  kiyohara #define WDC_READ_DATA_STREAM(chp) ({					\
     94  1.1  kiyohara 	_reg_write_4(SH4_PTEA, _PG_PCMCIA_IO16 >> _PG_PCMCIA_SHIFT);	\
     95  1.1  kiyohara 	*(chp)->c_data;							\
     96  1.1  kiyohara })
     97  1.1  kiyohara 
     98  1.1  kiyohara #endif
     99  1.1  kiyohara 
    100  1.1  kiyohara struct wd_softc {
    101  1.1  kiyohara #define WDF_LBA		0x0001
    102  1.1  kiyohara #define WDF_LBA48	0x0002
    103  1.1  kiyohara 	uint16_t sc_flags;
    104  1.1  kiyohara 
    105  1.1  kiyohara 	u_int sc_part;
    106  1.1  kiyohara 	u_int sc_unit;
    107  1.1  kiyohara 
    108  1.1  kiyohara 	uint64_t sc_capacity;
    109  1.1  kiyohara 	uint32_t sc_capacity28;
    110  1.1  kiyohara 
    111  1.1  kiyohara 	struct ataparams sc_params;
    112  1.1  kiyohara 	struct disklabel sc_label;
    113  1.1  kiyohara 	struct wdc_channel sc_channel;
    114  1.1  kiyohara };
    115  1.1  kiyohara 
    116  1.1  kiyohara struct wdc_command {
    117  1.1  kiyohara 	uint8_t drive;		/* drive id */
    118  1.1  kiyohara 
    119  1.1  kiyohara 	uint8_t r_command;	/* Parameters to upload to registers */
    120  1.1  kiyohara 	uint8_t r_head;
    121  1.1  kiyohara 	uint16_t r_cyl;
    122  1.1  kiyohara 	uint8_t r_sector;
    123  1.1  kiyohara 	uint8_t r_count;
    124  1.1  kiyohara 	uint8_t r_features;
    125  1.1  kiyohara 
    126  1.1  kiyohara 	uint16_t bcount;
    127  1.1  kiyohara 	void *data;
    128  1.1  kiyohara 
    129  1.1  kiyohara 	uint64_t r_blkno;
    130  1.1  kiyohara };
    131  1.1  kiyohara 
    132  1.1  kiyohara int	wdc_init(struct wd_softc *, u_int *);
    133  1.1  kiyohara int	wdccommand(struct wd_softc *, struct wdc_command *);
    134  1.1  kiyohara int	wdccommandext(struct wd_softc *, struct wdc_command *);
    135  1.1  kiyohara int	wdc_exec_read(struct wd_softc *, uint8_t, daddr_t, void *);
    136  1.1  kiyohara int	wdc_exec_identify(struct wd_softc *, void *);
    137  1.1  kiyohara 
    138  1.1  kiyohara #endif /* _STAND_WDVAR_H */
    139