pciide.c revision 1.9
11.9Skamil/*	$NetBSD: pciide.c,v 1.9 2015/07/11 10:32:45 kamil Exp $	*/
21.1Scdi
31.1Scdi/*-
41.1Scdi * Copyright (c) 2003 The NetBSD Foundation, Inc.
51.1Scdi * All rights reserved.
61.1Scdi *
71.1Scdi * Redistribution and use in source and binary forms, with or without
81.1Scdi * modification, are permitted provided that the following conditions
91.1Scdi * are met:
101.1Scdi * 1. Redistributions of source code must retain the above copyright
111.1Scdi *    notice, this list of conditions and the following disclaimer.
121.1Scdi * 2. Redistributions in binary form must reproduce the above copyright
131.1Scdi *    notice, this list of conditions and the following disclaimer in the
141.1Scdi *    documentation and/or other materials provided with the distribution.
151.1Scdi *
161.1Scdi * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Scdi * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Scdi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Scdi * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Scdi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Scdi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Scdi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Scdi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Scdi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Scdi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Scdi * POSSIBILITY OF SUCH DAMAGE.
271.1Scdi */
281.1Scdi
291.1Scdi#include <sys/types.h>
301.1Scdi#include <lib/libsa/stand.h>
311.1Scdi#include <mips/cpuregs.h>
321.1Scdi
331.1Scdi#include "boot.h"
341.1Scdi#include "wdvar.h"
351.1Scdi
361.4Stsutsui#define COBALT_IO_SPACE_BASE	0x10000000	/* XXX VT82C586 ISA I/O space */
371.4Stsutsui
381.1Scdiint
391.6Stsutsuipciide_init(struct wdc_channel *chp, u_int *unit)
401.1Scdi{
411.6Stsutsui	uint32_t cmdreg, ctlreg;
421.4Stsutsui	int i, compatchan = 0;
431.1Scdi
441.1Scdi	/*
451.1Scdi	 * two channels per chip, two drives per channel
461.1Scdi	 */
471.1Scdi	compatchan = *unit / PCIIDE_CHANNEL_NDEV;
481.1Scdi	if (compatchan >= PCIIDE_NUM_CHANNELS)
491.1Scdi		return (ENXIO);
501.1Scdi	*unit %= PCIIDE_CHANNEL_NDEV;
511.1Scdi
521.1Scdi	DPRINTF(("[pciide] unit: %d, channel: %d\n", *unit, compatchan));
531.1Scdi
541.1Scdi	/*
551.1Scdi	 * XXX map?
561.1Scdi	 */
571.4Stsutsui	cmdreg = MIPS_PHYS_TO_KSEG1(COBALT_IO_SPACE_BASE +
581.4Stsutsui	    PCIIDE_COMPAT_CMD_BASE(compatchan));
591.4Stsutsui	ctlreg = MIPS_PHYS_TO_KSEG1(COBALT_IO_SPACE_BASE +
601.4Stsutsui	    PCIIDE_COMPAT_CTL_BASE(compatchan));
611.4Stsutsui
621.9Skamil	/* set up cmd registers */
631.6Stsutsui	chp->c_cmdbase = (uint8_t *)cmdreg;
641.6Stsutsui	chp->c_data = (uint16_t *)(cmdreg + wd_data);
651.4Stsutsui	for (i = 0; i < WDC_NPORTS; i++)
661.4Stsutsui		chp->c_cmdreg[i] = chp->c_cmdbase + i;
671.4Stsutsui	/* set up shadow registers */
681.4Stsutsui	chp->c_cmdreg[wd_status]   = chp->c_cmdreg[wd_command];
691.4Stsutsui	chp->c_cmdreg[wd_features] = chp->c_cmdreg[wd_precomp];
701.4Stsutsui	/* set up ctl registers */
711.6Stsutsui	chp->c_ctlbase = (uint8_t *)ctlreg;
721.1Scdi
731.6Stsutsui	return 0;
741.1Scdi}
75