com_iof.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* $OpenBSD: com_iof.c,v 1.5 2009/10/16 00:15:46 miod Exp $ */
  2. /*
  3. * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  15. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  18. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. */
  27. #include <sys/param.h>
  28. #include <sys/systm.h>
  29. #include <sys/device.h>
  30. #include <sys/tty.h>
  31. #include <machine/autoconf.h>
  32. #include <machine/bus.h>
  33. #include <dev/ic/comreg.h>
  34. #include <dev/ic/comvar.h>
  35. #include <dev/ic/ns16550reg.h>
  36. #include <sgi/pci/iofvar.h>
  37. int com_iof_probe(struct device *, void *, void *);
  38. void com_iof_attach(struct device *, struct device *, void *);
  39. struct cfattach com_iof_ca = {
  40. sizeof(struct com_softc), com_iof_probe, com_iof_attach
  41. };
  42. extern struct cfdriver com_cd;
  43. int
  44. com_iof_probe(struct device *parent, void *match, void *aux)
  45. {
  46. struct cfdata *cf = match;
  47. struct iof_attach_args *iaa = aux;
  48. bus_space_tag_t iot = iaa->iaa_memt;
  49. bus_space_handle_t ioh;
  50. int rv = 0, console;
  51. if (strcmp(iaa->iaa_name, com_cd.cd_name) != 0)
  52. return 0;
  53. console = iaa->iaa_memh + iaa->iaa_base ==
  54. comconsiot->bus_base + comconsaddr;
  55. /* if it's in use as console, it's there. */
  56. if (!(console && !comconsattached)) {
  57. if (bus_space_subregion(iot, iaa->iaa_memh,
  58. iaa->iaa_base, COM_NPORTS, &ioh) == 0)
  59. rv = comprobe1(iot, ioh);
  60. } else
  61. rv = 1;
  62. /* make a config stanza with exact locators match over a generic line */
  63. if (cf->cf_loc[0] != -1)
  64. rv += rv;
  65. return rv;
  66. }
  67. void
  68. com_iof_attach(struct device *parent, struct device *self, void *aux)
  69. {
  70. struct com_softc *sc = (void *)self;
  71. struct iof_attach_args *iaa = aux;
  72. bus_space_handle_t ioh;
  73. int console;
  74. console = iaa->iaa_memh + iaa->iaa_base ==
  75. comconsiot->bus_base + comconsaddr;
  76. sc->sc_hwflags = 0;
  77. sc->sc_swflags = 0;
  78. sc->sc_frequency = iaa->iaa_clock;
  79. /* if it's in use as console, it's there. */
  80. if (!(console && !comconsattached)) {
  81. sc->sc_iot = iaa->iaa_memt;
  82. sc->sc_iobase = iaa->iaa_base;
  83. if (bus_space_subregion(iaa->iaa_memt, iaa->iaa_memh,
  84. iaa->iaa_base, COM_NPORTS, &ioh) != 0) {
  85. printf(": can't map registers\n");
  86. return;
  87. }
  88. } else {
  89. /*
  90. * If we are the console, reuse the existing bus_space
  91. * information, so that comcnattach() invokes bus_space_map()
  92. * with correct parameters.
  93. */
  94. sc->sc_iot = comconsiot;
  95. sc->sc_iobase = comconsaddr;
  96. if (comcnattach(sc->sc_iot, sc->sc_iobase, comconsrate,
  97. sc->sc_frequency, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
  98. panic("can't setup serial console");
  99. ioh = comconsioh;
  100. }
  101. sc->sc_ioh = ioh;
  102. com_attach_subr(sc);
  103. iof_intr_establish(parent, iaa->iaa_dev, IPL_TTY, comintr,
  104. (void *)sc, sc->sc_dev.dv_xname);
  105. }