Home | History | Annotate | Line # | Download | only in altboot
siisata.c revision 1.1
      1 /* $NetBSD: siisata.c,v 1.1 2011/01/23 01:05:30 nisimura Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tohru Nishimura.
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/param.h>
     33 
     34 #include <lib/libsa/stand.h>
     35 
     36 #include "globals.h"
     37 
     38 static uint32_t pciiobase = PCI_XIOBASE;
     39 
     40 int siisata_match(unsigned, void *);
     41 void *siisata_init(unsigned, void *);
     42 
     43 int
     44 siisata_match(unsigned tag, void *data)
     45 {
     46 	unsigned v;
     47 
     48 	v = pcicfgread(tag, PCI_ID_REG);
     49 	switch (v) {
     50 	case PCI_DEVICE(0x1095, 0x3112): /* SiI 3112 SATALink */
     51 	case PCI_DEVICE(0x1095, 0x3512): /*     3512 SATALink */
     52 	case PCI_DEVICE(0x1095, 0x3114): /* SiI 3114 SATALink */
     53 		return 1;
     54 	}
     55 	return 0;
     56 }
     57 
     58 void *
     59 siisata_init(unsigned tag, void *data)
     60 {
     61 	unsigned idreg;
     62 	int nchan, n;
     63 	struct dkdev_ata *l;
     64 
     65 	l = alloc(sizeof(struct dkdev_ata));
     66 	memset(l, 0, sizeof(struct dkdev_ata));
     67 	l->iobuf = allocaligned(512, 16);
     68 	l->tag = tag;
     69 
     70 	idreg = pcicfgread(tag, PCI_ID_REG);
     71 	l->bar[0] = pciiobase + (pcicfgread(tag, 0x10) &~ 01);
     72 	l->bar[1] = pciiobase + (pcicfgread(tag, 0x14) &~ 01);
     73 	l->bar[2] = pciiobase + (pcicfgread(tag, 0x18) &~ 01);
     74 	l->bar[3] = pciiobase + (pcicfgread(tag, 0x1c) &~ 01);
     75 	l->bar[4] = pciiobase + (pcicfgread(tag, 0x20) &~ 01);
     76 	l->bar[5] = pcicfgread(tag, 0x24) &~ 0x3ff;
     77 
     78 	if ((PCI_PRODUCT(idreg) & 0xf) == 0x2) {
     79 		/* 3112/3512 */
     80 		l->chan[0].cmd = l->bar[0];
     81 		l->chan[0].ctl = l->chan[0].alt = l->bar[1] | 02;
     82 		l->chan[0].dma = l->bar[4] + 0x0;
     83 		l->chan[1].cmd = l->bar[2];
     84 		l->chan[1].ctl = l->chan[1].alt = l->bar[3] | 02;
     85 		l->chan[1].dma = l->bar[4] + 0x8;
     86 		nchan = 2;
     87 	}
     88 	else {
     89 		/* 3114 - assume BA5 access is possible XXX */
     90 		l->chan[0].cmd = l->bar[5] + 0x080;
     91 		l->chan[0].ctl = l->chan[0].alt = (l->bar[5] + 0x088) | 02;
     92 		l->chan[1].cmd = l->bar[5] + 0x0c0;
     93 		l->chan[1].ctl = l->chan[1].alt = (l->bar[5] + 0x0c8) | 02;
     94 		l->chan[2].cmd = l->bar[5] + 0x280;
     95 		l->chan[2].ctl = l->chan[2].alt = (l->bar[5] + 0x288) | 02;
     96 		l->chan[3].cmd = l->bar[5] + 0x2c0;
     97 		l->chan[3].ctl = l->chan[3].alt = (l->bar[5] + 0x2c8) | 02;
     98 		nchan = 4;
     99 	}
    100 
    101 	/* configure PIO transfer mode */
    102 	pcicfgwrite(tag, 0x80, 0x00);
    103 	pcicfgwrite(tag, 0x84, 0x00);
    104 
    105 	for (n = 0; n < nchan; n++) {
    106 		if (satapresense(l, n)) {
    107 			/* drive present, now check whether soft reset works */
    108 			if (perform_atareset(l, n)) {
    109 				printf("port %d device present\n", n);
    110 				l->presense[n] = 1;
    111 			}
    112 		} else
    113 			l->presense[n] = 0;
    114 	}
    115 	return l;
    116 }
    117