isa.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* $OpenBSD: isa.c,v 1.46 2015/05/25 15:19:22 miod Exp $ */
  2. /* $NetBSD: isa.c,v 1.85 1996/05/14 00:31:04 thorpej Exp $ */
  3. /*
  4. * Copyright (c) 1997, Jason Downs. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
  16. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. /*-
  28. * Copyright (c) 1993, 1994 Charles Hannum. All rights reserved.
  29. *
  30. * Redistribution and use in source and binary forms, with or without
  31. * modification, are permitted provided that the following conditions
  32. * are met:
  33. * 1. Redistributions of source code must retain the above copyright
  34. * notice, this list of conditions and the following disclaimer.
  35. * 2. Redistributions in binary form must reproduce the above copyright
  36. * notice, this list of conditions and the following disclaimer in the
  37. * documentation and/or other materials provided with the distribution.
  38. * 3. All advertising materials mentioning features or use of this software
  39. * must display the following acknowledgement:
  40. * This product includes software developed by Charles Hannum.
  41. * 4. The name of the author may not be used to endorse or promote products
  42. * derived from this software without specific prior written permission.
  43. *
  44. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  45. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  46. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  47. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  48. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  49. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  50. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  51. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  52. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  53. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #include <sys/param.h>
  56. #include <sys/systm.h>
  57. #include <sys/kernel.h>
  58. #include <sys/conf.h>
  59. #include <sys/malloc.h>
  60. #include <sys/device.h>
  61. #include <sys/extent.h>
  62. #include <dev/isa/isareg.h>
  63. #include <dev/isa/isavar.h>
  64. #include <dev/isa/isadmareg.h>
  65. int isamatch(struct device *, void *, void *);
  66. void isaattach(struct device *, struct device *, void *);
  67. extern int autoconf_verbose;
  68. struct cfattach isa_ca = {
  69. sizeof(struct isa_softc), isamatch, isaattach
  70. };
  71. struct cfdriver isa_cd = {
  72. NULL, "isa", DV_DULL, 1
  73. };
  74. int
  75. isamatch(parent, match, aux)
  76. struct device *parent;
  77. void *match, *aux;
  78. {
  79. struct cfdata *cf = match;
  80. struct isabus_attach_args *iba = aux;
  81. if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
  82. return (0);
  83. /* XXX check other indicators */
  84. return (1);
  85. }
  86. void
  87. isaattach(parent, self, aux)
  88. struct device *parent, *self;
  89. void *aux;
  90. {
  91. struct isa_softc *sc = (struct isa_softc *)self;
  92. struct isabus_attach_args *iba = aux;
  93. isa_attach_hook(parent, self, iba);
  94. printf("\n");
  95. sc->sc_iot = iba->iba_iot;
  96. sc->sc_memt = iba->iba_memt;
  97. #if NISADMA > 0
  98. sc->sc_dmat = iba->iba_dmat;
  99. #endif /* NISADMA > 0 */
  100. sc->sc_ic = iba->iba_ic;
  101. #if NISAPNP > 0
  102. isapnp_isa_attach_hook(sc);
  103. #endif
  104. #if NISADMA > 0
  105. /*
  106. * Map the registers used by the ISA DMA controller.
  107. * XXX Should be done in the isadmaattach routine.. but the delay
  108. * XXX port makes it troublesome. Note that these aren't really
  109. * XXX valid on ISA busses without DMA.
  110. */
  111. if (bus_space_map(sc->sc_iot, IO_DMA1, DMA1_IOSIZE, 0, &sc->sc_dma1h))
  112. panic("isaattach: can't map DMA controller #1");
  113. if (bus_space_map(sc->sc_iot, IO_DMA2, DMA2_IOSIZE, 0, &sc->sc_dma2h))
  114. panic("isaattach: can't map DMA controller #2");
  115. if (bus_space_map(sc->sc_iot, IO_DMAPG, 0xf, 0, &sc->sc_dmapgh))
  116. panic("isaattach: can't map DMA page registers");
  117. /*
  118. * Map port 0x84, which causes a 1.25us delay when read.
  119. * We do this now, since several drivers need it.
  120. * XXX this port doesn't exist on all ISA busses...
  121. */
  122. if (bus_space_subregion(sc->sc_iot, sc->sc_dmapgh, 0x04, 1,
  123. &sc->sc_delaybah))
  124. #else /* NISADMA > 0 */
  125. if (bus_space_map(sc->sc_iot, IO_DMAPG + 0x4, 0x1, 0,
  126. &sc->sc_delaybah))
  127. #endif /* NISADMA > 0 */
  128. panic("isaattach: can't map `delay port'"); /* XXX */
  129. TAILQ_INIT(&sc->sc_subdevs);
  130. config_scan(isascan, self);
  131. }
  132. int
  133. isaprint(aux, isa)
  134. void *aux;
  135. const char *isa;
  136. {
  137. struct isa_attach_args *ia = aux;
  138. int irq, nirq;
  139. int dma, ndma;
  140. if (ia->ia_iosize)
  141. printf(" port 0x%x", ia->ia_iobase);
  142. if (ia->ia_iosize > 1)
  143. printf("/%d", ia->ia_iosize);
  144. if (ia->ia_msize)
  145. printf(" iomem 0x%x", ia->ia_maddr);
  146. if (ia->ia_msize > 1)
  147. printf("/%d", ia->ia_msize);
  148. nirq = ia->ipa_nirq;
  149. if (nirq < 0 || nirq > nitems(ia->ipa_irq))
  150. nirq = 1;
  151. for (irq = 0; irq < nirq; irq++)
  152. if (ia->ipa_irq[irq].num != IRQUNK)
  153. printf(" irq %d", ia->ipa_irq[irq].num);
  154. ndma = ia->ipa_ndrq;
  155. if (ndma < 0 || ndma > nitems(ia->ipa_drq))
  156. ndma = 2;
  157. for (dma = 0; dma < ndma; dma++)
  158. if (ia->ipa_drq[dma].num != DRQUNK) {
  159. if (dma == 0)
  160. printf(" drq");
  161. else
  162. printf(" drq%d", dma + 1);
  163. printf(" %d", ia->ipa_drq[dma].num);
  164. }
  165. return (UNCONF);
  166. }
  167. void
  168. isascan(parent, match)
  169. struct device *parent;
  170. void *match;
  171. {
  172. struct isa_softc *sc = (struct isa_softc *)parent;
  173. struct device *dev = match;
  174. struct cfdata *cf = dev->dv_cfdata;
  175. struct isa_attach_args ia;
  176. ia.ia_iot = sc->sc_iot;
  177. ia.ia_memt = sc->sc_memt;
  178. #if NISADMA > 0
  179. ia.ia_dmat = sc->sc_dmat;
  180. #endif /* NISADMA > 0 */
  181. ia.ia_ic = sc->sc_ic;
  182. ia.ia_iobase = cf->cf_iobase;
  183. ia.ia_iosize = 0x666;
  184. ia.ia_maddr = cf->cf_maddr;
  185. ia.ia_msize = cf->cf_msize;
  186. ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq;
  187. ia.ipa_nirq = ia.ia_irq == IRQUNK ? 0 : 1;
  188. ia.ia_drq = cf->cf_drq;
  189. ia.ia_drq2 = cf->cf_drq2;
  190. ia.ipa_ndrq = 2;
  191. ia.ia_delaybah = sc->sc_delaybah;
  192. if (cf->cf_fstate == FSTATE_STAR) {
  193. struct isa_attach_args ia2 = ia;
  194. if (autoconf_verbose)
  195. printf(">>> probing for %s*\n",
  196. cf->cf_driver->cd_name);
  197. while ((*cf->cf_attach->ca_match)(parent, dev, &ia2) > 0) {
  198. #if !defined(__NO_ISA_INTR_CHECK)
  199. if ((ia2.ia_irq != IRQUNK) &&
  200. !isa_intr_check(sc->sc_ic, ia2.ia_irq, IST_EDGE)) {
  201. printf("%s%d: irq %d already in use\n",
  202. cf->cf_driver->cd_name, cf->cf_unit,
  203. ia2.ia_irq);
  204. ia2 = ia;
  205. break;
  206. }
  207. #endif
  208. if (autoconf_verbose)
  209. printf(">>> probe for %s* clone into %s%d\n",
  210. cf->cf_driver->cd_name,
  211. cf->cf_driver->cd_name, cf->cf_unit);
  212. if (ia2.ia_iosize == 0x666) {
  213. printf("%s: iosize not repaired by driver\n",
  214. sc->sc_dev.dv_xname);
  215. ia2.ia_iosize = 0;
  216. }
  217. config_attach(parent, dev, &ia2, isaprint);
  218. dev = config_make_softc(parent, cf);
  219. #if NISADMA > 0
  220. if (ia2.ia_drq != DRQUNK)
  221. ISA_DRQ_ALLOC((struct device *)sc, ia2.ia_drq);
  222. if (ia2.ia_drq2 != DRQUNK)
  223. ISA_DRQ_ALLOC((struct device *)sc, ia2.ia_drq2);
  224. #endif /* NISAMDA > 0 */
  225. ia2 = ia;
  226. }
  227. if (autoconf_verbose)
  228. printf(">>> probing for %s* finished\n",
  229. cf->cf_driver->cd_name);
  230. free(dev, M_DEVBUF, 0);
  231. return;
  232. }
  233. if (autoconf_verbose)
  234. printf(">>> probing for %s%d\n", cf->cf_driver->cd_name,
  235. cf->cf_unit);
  236. if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0) {
  237. #if !defined(__NO_ISA_INTR_CHECK)
  238. if ((ia.ia_irq != IRQUNK) &&
  239. !isa_intr_check(sc->sc_ic, ia.ia_irq, IST_EDGE)) {
  240. printf("%s%d: irq %d already in use\n",
  241. cf->cf_driver->cd_name, cf->cf_unit, ia.ia_irq);
  242. free(dev, M_DEVBUF, 0);
  243. } else {
  244. #endif
  245. if (autoconf_verbose)
  246. printf(">>> probing for %s%d succeeded\n",
  247. cf->cf_driver->cd_name, cf->cf_unit);
  248. config_attach(parent, dev, &ia, isaprint);
  249. #if NISADMA > 0
  250. if (ia.ia_drq != DRQUNK)
  251. ISA_DRQ_ALLOC((struct device *)sc, ia.ia_drq);
  252. if (ia.ia_drq2 != DRQUNK)
  253. ISA_DRQ_ALLOC((struct device *)sc, ia.ia_drq2);
  254. #endif /* NISAMDA > 0 */
  255. #if !defined(__NO_ISA_INTR_CHECK)
  256. }
  257. #endif
  258. } else {
  259. if (autoconf_verbose)
  260. printf(">>> probing for %s%d failed\n",
  261. cf->cf_driver->cd_name, cf->cf_unit);
  262. free(dev, M_DEVBUF, 0);
  263. }
  264. }
  265. char *
  266. isa_intr_typename(type)
  267. int type;
  268. {
  269. switch (type) {
  270. case IST_NONE:
  271. return ("none");
  272. case IST_PULSE:
  273. return ("pulsed");
  274. case IST_EDGE:
  275. return ("edge-triggered");
  276. case IST_LEVEL:
  277. return ("level-triggered");
  278. default:
  279. panic("isa_intr_typename: invalid type %d", type);
  280. }
  281. }