dpt_eisa.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* $OpenBSD: dpt_eisa.c,v 1.4 2008/05/13 02:24:08 brad Exp $ */
  2. /* $NetBSD: dpt_eisa.c,v 1.2 1999/10/18 21:59:19 ad Exp $ */
  3. /*
  4. * Copyright (c) 1999 Andy Doran <ad@NetBSD.org>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. *
  28. */
  29. /*
  30. * EISA front-end for DPT EATA SCSI driver.
  31. */
  32. #include <sys/types.h>
  33. #include <sys/param.h>
  34. #include <sys/systm.h>
  35. #include <sys/device.h>
  36. #include <machine/bus.h>
  37. #include <machine/intr.h>
  38. #ifdef __NetBSD__
  39. #include <dev/scsipi/scsi_all.h>
  40. #include <dev/scsipi/scsipi_all.h>
  41. #include <dev/scsipi/scsiconf.h>
  42. #endif /* __NetBSD__ */
  43. #ifdef __OpenBSD__
  44. #include <scsi/scsi_all.h>
  45. #include <scsi/scsiconf.h>
  46. #endif /* __OpenBSD__ */
  47. #include <dev/eisa/eisavar.h>
  48. #include <dev/eisa/eisadevs.h>
  49. #include <dev/ic/dptreg.h>
  50. #include <dev/ic/dptvar.h>
  51. #define DPT_EISA_SLOT_OFFSET 0x0c00
  52. #define DPT_EISA_IOSIZE 0x0100
  53. #define DPT_EISA_IOCONF 0x90
  54. #define DPT_EISA_EATA_REG_OFFSET 0x88
  55. int dpt_eisa_irq(bus_space_tag_t, bus_space_handle_t, int *);
  56. #ifdef __NetBSD__
  57. int dpt_eisa_match(struct device *, struct cfdata *, void *);
  58. #endif /* __NetBSD__ */
  59. #ifdef __OpenBSD__
  60. int dpt_eisa_match(struct device *, void *, void *);
  61. #endif /* __OpenBSD__ */
  62. void dpt_eisa_attach(struct device *, struct device *, void *);
  63. struct cfattach dpt_eisa_ca = {
  64. sizeof(struct dpt_softc), dpt_eisa_match, dpt_eisa_attach
  65. };
  66. const char *dpt_eisa_boards[] = {
  67. "DPT2402",
  68. "DPTA401",
  69. "DPTA402",
  70. "DPTA410",
  71. "DPTA411",
  72. "DPTA412",
  73. "DPTA420",
  74. "DPTA501",
  75. "DPTA502",
  76. "DPTA701",
  77. "DPTBC01",
  78. "NEC8200", /* OEM */
  79. "ATT2408", /* OEM */
  80. NULL
  81. };
  82. int
  83. dpt_eisa_irq(iot, ioh, irq)
  84. bus_space_tag_t iot;
  85. bus_space_handle_t ioh;
  86. int *irq;
  87. {
  88. switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
  89. case 0x08:
  90. *irq = 11;
  91. break;
  92. case 0x10:
  93. *irq = 15;
  94. break;
  95. case 0x20:
  96. *irq = 14;
  97. break;
  98. default:
  99. return (-1);
  100. }
  101. return (0);
  102. }
  103. int
  104. dpt_eisa_match(parent, match, aux)
  105. struct device *parent;
  106. #ifdef __NetBSD__
  107. struct cfdata *match;
  108. #endif /* __NetBSD__ */
  109. #ifdef __OpenBSD__
  110. void *match;
  111. #endif /* __OpenBSD__ */
  112. void *aux;
  113. {
  114. struct eisa_attach_args *ea;
  115. int i;
  116. ea = aux;
  117. for (i = 0; dpt_eisa_boards[i] != NULL; i++)
  118. if (strcmp(ea->ea_idstring, dpt_eisa_boards[i]) == 0)
  119. break;
  120. return (dpt_eisa_boards[i] != NULL);
  121. }
  122. void
  123. dpt_eisa_attach(parent, self, aux)
  124. struct device *parent, *self;
  125. void *aux;
  126. {
  127. struct eisa_attach_args *ea;
  128. bus_space_handle_t ioh;
  129. eisa_chipset_tag_t ec;
  130. eisa_intr_handle_t ih;
  131. struct dpt_softc *sc;
  132. bus_space_tag_t iot;
  133. const char *intrstr;
  134. int irq;
  135. ea = aux;
  136. sc = (struct dpt_softc *)self;
  137. iot = ea->ea_iot;
  138. ec = ea->ea_ec;
  139. printf(": ");
  140. if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
  141. DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
  142. printf("can't map i/o space\n");
  143. return;
  144. }
  145. sc->sc_iot = iot;
  146. sc->sc_ioh = ioh;
  147. sc->sc_dmat = ea->ea_dmat;
  148. /* Map and establish the interrupt. */
  149. if (dpt_eisa_irq(iot, ioh, &irq)) {
  150. printf("HBA on invalid IRQ (%d)\n", irq);
  151. return;
  152. }
  153. if (eisa_intr_map(ec, irq, &ih)) {
  154. printf("can't map interrupt (%d)\n", irq);
  155. return;
  156. }
  157. intrstr = eisa_intr_string(ec, ih);
  158. #ifdef __NetBSD__
  159. sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
  160. dpt_intr, sc);
  161. #endif /* __NetBSD__ */
  162. #ifdef __OpenBSD__
  163. sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
  164. dpt_intr, sc, sc->sc_dv.dv_xname);
  165. #endif /* __OpenBSD__ */
  166. if (sc->sc_ih == NULL) {
  167. printf("can't establish interrupt");
  168. if (intrstr != NULL)
  169. printf(" at %s", intrstr);
  170. printf("\n");
  171. return;
  172. }
  173. /* Read the EATA configuration */
  174. if (dpt_readcfg(sc)) {
  175. printf("%s: readcfg failed - see dpt(4)\n",
  176. sc->sc_dv.dv_xname);
  177. return;
  178. }
  179. /* Now attach to the bus-independent code */
  180. dpt_init(sc, intrstr);
  181. }