com_ioc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* $OpenBSD: com_ioc.c,v 1.9 2012/10/03 22:46:09 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 <machine/intr.h>
  34. #include <dev/ic/comreg.h>
  35. #include <dev/ic/comvar.h>
  36. #include <dev/ic/ns16550reg.h>
  37. #include <sgi/pci/iocvar.h>
  38. int com_ioc_probe(struct device *, void *, void *);
  39. void com_ioc_attach(struct device *, struct device *, void *);
  40. struct cfattach com_ioc_ca = {
  41. sizeof(struct com_softc), com_ioc_probe, com_ioc_attach
  42. };
  43. extern struct cfdriver com_cd;
  44. int
  45. com_ioc_probe(struct device *parent, void *match, void *aux)
  46. {
  47. struct cfdata *cf = match;
  48. struct ioc_attach_args *iaa = aux;
  49. bus_space_tag_t iot = iaa->iaa_memt;
  50. bus_space_handle_t ioh;
  51. int rv = 0, console = 0;
  52. if (strcmp(iaa->iaa_name, com_cd.cd_name) != 0)
  53. return 0;
  54. if (comconsiot != NULL)
  55. console = iaa->iaa_memh + iaa->iaa_base ==
  56. comconsiot->bus_base + comconsaddr;
  57. /* if it's in use as console, it's there. */
  58. if (!(console && !comconsattached)) {
  59. if (bus_space_subregion(iot, iaa->iaa_memh,
  60. iaa->iaa_base, COM_NPORTS, &ioh) == 0)
  61. rv = comprobe1(iot, ioh);
  62. } else
  63. rv = 1;
  64. /* make a config stanza with exact locators match over a generic line */
  65. if (cf->cf_loc[0] != -1)
  66. rv += rv;
  67. return rv;
  68. }
  69. void
  70. com_ioc_attach(struct device *parent, struct device *self, void *aux)
  71. {
  72. struct com_softc *sc = (void *)self;
  73. struct ioc_attach_args *iaa = aux;
  74. bus_space_handle_t ioh;
  75. int console = 0;
  76. if (comconsiot != NULL)
  77. console = iaa->iaa_memh + iaa->iaa_base ==
  78. comconsiot->bus_base + comconsaddr;
  79. sc->sc_hwflags = 0;
  80. sc->sc_swflags = 0;
  81. sc->sc_frequency = 22000000 / 3;
  82. /* if it's in use as console, it's there. */
  83. if (!(console && !comconsattached)) {
  84. sc->sc_iot = iaa->iaa_memt;
  85. sc->sc_iobase = iaa->iaa_base;
  86. if (bus_space_subregion(iaa->iaa_memt, iaa->iaa_memh,
  87. iaa->iaa_base, COM_NPORTS, &ioh) != 0) {
  88. printf(": can't map registers\n");
  89. return;
  90. }
  91. } else {
  92. /*
  93. * If we are the console, reuse the existing bus_space
  94. * information, so that comcnattach() invokes bus_space_map()
  95. * with correct parameters.
  96. */
  97. sc->sc_iot = comconsiot;
  98. sc->sc_iobase = comconsaddr;
  99. if (comcnattach(sc->sc_iot, sc->sc_iobase, comconsrate,
  100. sc->sc_frequency, (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8))
  101. panic("can't setup serial console");
  102. ioh = comconsioh;
  103. }
  104. sc->sc_ioh = ioh;
  105. com_attach_subr(sc);
  106. ioc_intr_establish(parent, iaa->iaa_dev, IPL_TTY, comintr,
  107. (void *)sc, sc->sc_dev.dv_xname);
  108. }