1 /* $OpenBSD: wdc_isapnp.c,v 1.13 2022/04/06 18:59:29 naddy Exp $ */
2 /* $NetBSD: wdc_isapnp.c,v 1.13 1999/03/22 10:00:12 mycroft Exp $ */
3
4 /*-
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Charles M. Hannum and by Onno van der Linden.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 #include <sys/malloc.h>
37
38 #include <machine/bus.h>
39 #include <machine/intr.h>
40
41 #include <dev/isa/isavar.h>
42 #include <dev/isa/isadmavar.h>
43
44 #include <dev/ata/atavar.h>
45 #include <dev/ic/wdcreg.h>
46 #include <dev/ic/wdcvar.h>
47
48 struct wdc_isapnp_softc {
49 struct wdc_softc sc_wdcdev;
50 struct channel_softc *wdc_chanptr;
51 struct channel_softc wdc_channel;
52 isa_chipset_tag_t sc_ic;
53 void *sc_ih;
54 int sc_drq;
55 };
56
57 int wdc_isapnp_match(struct device *, void *, void *);
58 void wdc_isapnp_attach(struct device *, struct device *, void *);
59
60 const struct cfattach wdc_isapnp_ca = {
61 sizeof(struct wdc_isapnp_softc), wdc_isapnp_match, wdc_isapnp_attach
62 };
63
64 int
65 wdc_isapnp_match(struct device *parent, void *match, void *aux)
66 {
67 struct isa_attach_args *ipa = aux;
68
69 if (ipa->ipa_nio != 2 ||
70 ipa->ipa_nmem != 0 ||
71 ipa->ipa_nmem32 != 0 ||
72 ipa->ipa_nirq != 1 ||
73 ipa->ipa_ndrq > 1)
74 return 0;
75
76 return (1);
77 }
78
79 void
80 wdc_isapnp_attach(struct device *parent, struct device *self, void *aux)
81 {
82 struct wdc_isapnp_softc *sc = (void *)self;
83 struct isa_attach_args *ipa = aux;
84
85
86 sc->wdc_channel.cmd_iot = ipa->ia_iot;
87 sc->wdc_channel.ctl_iot = ipa->ia_iot;
88
89 /*
90 * An IDE controller can feed us the regions in any order. Pass
91 * them along with the 8-byte region in sc_ad.ioh, and the other
92 * (2 byte) region in auxioh.
93 */
94 if (ipa->ipa_io[0].length == 8) {
95 sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
96 sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
97 } else {
98 sc->wdc_channel.cmd_ioh = ipa->ipa_io[1].h;
99 sc->wdc_channel.ctl_ioh = ipa->ipa_io[0].h;
100 }
101 sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
102 sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
103
104 sc->sc_ic = ipa->ia_ic;
105 sc->sc_ih = isa_intr_establish(ipa->ia_ic, ipa->ipa_irq[0].num,
106 ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel,
107 sc->sc_wdcdev.sc_dev.dv_xname);
108
109 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
110 sc->sc_wdcdev.PIO_cap = 0;
111 sc->wdc_chanptr = &sc->wdc_channel;
112 sc->sc_wdcdev.channels = &sc->wdc_chanptr;
113 sc->sc_wdcdev.nchannels = 1;
114 sc->wdc_channel.channel = 0;
115 sc->wdc_channel.wdc = &sc->sc_wdcdev;
116 sc->wdc_channel.ch_queue = wdc_alloc_queue();
117 if (sc->wdc_channel.ch_queue == NULL) {
118 printf(": cannot allocate channel queue\n");
119 return;
120 }
121
122 printf("\n");
123 wdcattach(&sc->wdc_channel);
124 wdc_print_current_modes(&sc->wdc_channel);
125 }
Cache object: 3a55ca4519f68d70cfdd1c9cd678bfb3
|