wdc_isapnp.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* $OpenBSD: wdc_isapnp.c,v 1.10 2011/06/29 12:17:40 tedu Exp $ */
  2. /* $NetBSD: wdc_isapnp.c,v 1.13 1999/03/22 10:00:12 mycroft Exp $ */
  3. /*-
  4. * Copyright (c) 1998 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Charles M. Hannum and by Onno van der Linden.
  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. #include <sys/types.h>
  32. #include <sys/param.h>
  33. #include <sys/systm.h>
  34. #include <sys/device.h>
  35. #include <sys/malloc.h>
  36. #include <machine/bus.h>
  37. #include <machine/intr.h>
  38. #include <dev/isa/isavar.h>
  39. #include <dev/isa/isadmavar.h>
  40. #include <dev/ata/atavar.h>
  41. #include <dev/ic/wdcreg.h>
  42. #include <dev/ic/wdcvar.h>
  43. struct wdc_isapnp_softc {
  44. struct wdc_softc sc_wdcdev;
  45. struct channel_softc *wdc_chanptr;
  46. struct channel_softc wdc_channel;
  47. isa_chipset_tag_t sc_ic;
  48. void *sc_ih;
  49. int sc_drq;
  50. };
  51. int wdc_isapnp_match(struct device *, void *, void *);
  52. void wdc_isapnp_attach(struct device *, struct device *, void *);
  53. struct cfattach wdc_isapnp_ca = {
  54. sizeof(struct wdc_isapnp_softc), wdc_isapnp_match, wdc_isapnp_attach
  55. };
  56. int
  57. wdc_isapnp_match(parent, match, aux)
  58. struct device *parent;
  59. void *match;
  60. void *aux;
  61. {
  62. struct isa_attach_args *ipa = aux;
  63. if (ipa->ipa_nio != 2 ||
  64. ipa->ipa_nmem != 0 ||
  65. ipa->ipa_nmem32 != 0 ||
  66. ipa->ipa_nirq != 1 ||
  67. ipa->ipa_ndrq > 1)
  68. return 0;
  69. return (1);
  70. }
  71. void
  72. wdc_isapnp_attach(parent, self, aux)
  73. struct device *parent, *self;
  74. void *aux;
  75. {
  76. struct wdc_isapnp_softc *sc = (void *)self;
  77. struct isa_attach_args *ipa = aux;
  78. sc->wdc_channel.cmd_iot = ipa->ia_iot;
  79. sc->wdc_channel.ctl_iot = ipa->ia_iot;
  80. /*
  81. * An IDE controller can feed us the regions in any order. Pass
  82. * them along with the 8-byte region in sc_ad.ioh, and the other
  83. * (2 byte) region in auxioh.
  84. */
  85. if (ipa->ipa_io[0].length == 8) {
  86. sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
  87. sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
  88. } else {
  89. sc->wdc_channel.cmd_ioh = ipa->ipa_io[1].h;
  90. sc->wdc_channel.ctl_ioh = ipa->ipa_io[0].h;
  91. }
  92. sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
  93. sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
  94. sc->sc_ic = ipa->ia_ic;
  95. sc->sc_ih = isa_intr_establish(ipa->ia_ic, ipa->ipa_irq[0].num,
  96. ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel,
  97. sc->sc_wdcdev.sc_dev.dv_xname);
  98. sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
  99. sc->sc_wdcdev.PIO_cap = 0;
  100. sc->wdc_chanptr = &sc->wdc_channel;
  101. sc->sc_wdcdev.channels = &sc->wdc_chanptr;
  102. sc->sc_wdcdev.nchannels = 1;
  103. sc->wdc_channel.channel = 0;
  104. sc->wdc_channel.wdc = &sc->sc_wdcdev;
  105. sc->wdc_channel.ch_queue = wdc_alloc_queue();
  106. if (sc->wdc_channel.ch_queue == NULL) {
  107. printf(": cannot allocate channel queue\n");
  108. return;
  109. }
  110. printf("\n");
  111. wdcattach(&sc->wdc_channel);
  112. wdc_print_current_modes(&sc->wdc_channel);
  113. }