Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / sandpoint / stand / netboot / pciide.c
blobe0cc605f9d6b94577f17ab2b6ce1e6b415d26675
1 /* $NetBSD: pciide.c,v 1.6 2008/05/12 09:29:56 nisimura Exp $ */
3 /*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura.
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.
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.
32 #include <sys/param.h>
33 #include <sys/disklabel.h>
35 #include <dev/ic/wdcreg.h>
36 #include <dev/ata/atareg.h>
38 #include <lib/libsa/stand.h>
39 #include "globals.h"
42 * - no vtophys() translation, vaddr_t == paddr_t.
44 #define DEVTOV(pa) (uint32_t)(pa)
47 * cmdide
48 * iteide
49 * viaide
50 * slide
53 int pciide_match(unsigned, void *);
54 void *pciide_init(unsigned, void *);
56 #define PCIIDE_INTERFACE_PCI(chan) (0x01 << (2 * (chan)))
58 /* native: PCI BAR0-3 */
59 static const struct {
60 int cmd, ctl;
61 } pcibar[2] = {
62 { 0x10, 0x14 },
63 { 0x18, 0x1c },
65 /* legacy: ISA/PCI IO space */
66 static const struct {
67 int cmd, ctl;
68 } compat[2] = {
69 { 0x1f0, 0x3f6 },
70 { 0x170, 0x376 },
73 int
74 pciide_match(unsigned tag, void *data)
76 unsigned v;
78 v = pcicfgread(tag, PCI_ID_REG);
79 switch (v) {
80 case PCI_DEVICE(0x1095, 0x0680): /* SiI 0680 IDE */
81 case PCI_DEVICE(0x1283, 0x8211): /* ITE 8211 IDE */
82 case PCI_DEVICE(0x1106, 0x1571): /* VIA 82C586 IDE */
83 case PCI_DEVICE(0x10ad, 0x0105): /* Symphony Labs 82C105 IDE */
84 return 1;
86 return 0;
89 void *
90 pciide_init(unsigned tag, void *data)
92 int ch, i;
93 unsigned val;
94 struct atac_softc *l;
95 struct atac_channel *cp;
97 l = alloc(sizeof(struct atac_softc));
98 memset(l, 0, sizeof(struct atac_softc));
99 val = pcicfgread(tag, PCI_CLASS_REG);
100 for (ch = 0; ch < 2; ch += 1) {
101 cp = &l->channel[ch];
102 if (PCIIDE_INTERFACE_PCI(ch) & val) {
103 cp->c_cmdbase =
104 (void *)DEVTOV(~03 & pcicfgread(tag, pcibar[ch].cmd));
105 cp->c_ctlbase =
106 (void *)DEVTOV(~03 & pcicfgread(tag, pcibar[ch].ctl));
107 cp->c_data = (u_int16_t *)(cp->c_cmdbase + wd_data);
108 for (i = 0; i < 8; i++)
109 cp->c_cmdreg[i] = cp->c_cmdbase + i;
110 cp->c_cmdreg[wd_status] = cp->c_cmdreg[wd_command];
111 cp->c_cmdreg[wd_features] = cp->c_cmdreg[wd_precomp];
113 else {
114 uint32_t pciiobase = 0xfe000000; /* !!! */
115 cp->c_cmdbase =
116 (void *)DEVTOV(pciiobase + compat[ch].cmd);
117 cp->c_ctlbase =
118 (void *)DEVTOV(pciiobase + compat[ch].ctl);
119 cp->c_data = (u_int16_t *)(cp->c_cmdbase + wd_data);
120 for (i = 0; i < 8; i++)
121 cp->c_cmdreg[i] = cp->c_cmdbase + i;
122 cp->c_cmdreg[wd_status] = cp->c_cmdreg[wd_command];
123 cp->c_cmdreg[wd_features] = cp->c_cmdreg[wd_precomp];
125 cp->compatchan = ch;
127 l->chvalid = 03 & (unsigned)data;
128 l->tag = tag;
129 return l;