1 /* $NetBSD: pciide.c,v 1.6 2008/05/12 09:29:56 nisimura Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
42 * - no vtophys() translation, vaddr_t == paddr_t.
44 #define DEVTOV(pa) (uint32_t)(pa)
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 */
65 /* legacy: ISA/PCI IO space */
74 pciide_match(unsigned tag
, void *data
)
78 v
= pcicfgread(tag
, PCI_ID_REG
);
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 */
90 pciide_init(unsigned tag
, void *data
)
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
) {
104 (void *)DEVTOV(~03 & pcicfgread(tag
, pcibar
[ch
].cmd
));
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
];
114 uint32_t pciiobase
= 0xfe000000; /* !!! */
116 (void *)DEVTOV(pciiobase
+ compat
[ch
].cmd
);
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
];
127 l
->chvalid
= 03 & (unsigned)data
;