xbox.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* $OpenBSD: xbox.c,v 1.3 2006/06/02 20:00:56 miod Exp $ */
  2. /*
  3. * Copyright (c) 1999 Jason L. Wright (jason@thought.net)
  4. * 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 ``AS IS'' AND ANY EXPRESS OR
  16. * 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 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)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  24. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. /*
  28. * Driver for the Sun SBus Expansion Subsystem
  29. */
  30. #include <sys/param.h>
  31. #include <sys/systm.h>
  32. #include <sys/kernel.h>
  33. #include <sys/errno.h>
  34. #include <sys/ioctl.h>
  35. #include <sys/syslog.h>
  36. #include <sys/device.h>
  37. #include <sys/malloc.h>
  38. #include <machine/autoconf.h>
  39. #include <machine/bus.h>
  40. #include <machine/cpu.h>
  41. #include <dev/sbus/sbusvar.h>
  42. #include <dev/sbus/xboxreg.h>
  43. #include <dev/sbus/xboxvar.h>
  44. int xboxmatch(struct device *, void *, void *);
  45. void xboxattach(struct device *, struct device *, void *);
  46. int xboxprint(void *, const char *);
  47. int xbox_fix_range(struct xbox_softc *sc, struct sbus_softc *sbp);
  48. struct cfattach xbox_ca = {
  49. sizeof (struct xbox_softc), xboxmatch, xboxattach
  50. };
  51. struct cfdriver xbox_cd = {
  52. NULL, "xbox", DV_DULL
  53. };
  54. int
  55. xboxmatch(struct device *parent, void *cf, void *aux)
  56. {
  57. struct sbus_attach_args *sa = aux;
  58. if (strcmp("SUNW,xbox", sa->sa_name))
  59. return (0);
  60. return (1);
  61. }
  62. void
  63. xboxattach(struct device *parent, struct device *self, void *aux)
  64. {
  65. struct xbox_softc *sc = (struct xbox_softc *)self;
  66. struct sbus_attach_args *sa = aux;
  67. int node = sa->sa_node;
  68. struct xbox_attach_args xa;
  69. bus_space_handle_t write0;
  70. char *s;
  71. s = getpropstring(node, "model");
  72. printf(": model %s", s);
  73. s = getpropstring(node, "child-present");
  74. if (strcmp(s, "false") == 0) {
  75. printf(": no devices\n");
  76. return;
  77. }
  78. sc->sc_key = getpropint(node, "write0-key", -1);
  79. sc->sc_node = node;
  80. /*
  81. * Setup transparent access
  82. */
  83. if (sbus_bus_map(sa->sa_bustag, sa->sa_reg[0].sbr_slot,
  84. sa->sa_reg[0].sbr_offset, sa->sa_reg[0].sbr_size, 0, 0,
  85. &write0) != 0) {
  86. printf(": couldn't map write 0 register\n");
  87. return;
  88. }
  89. bus_space_write_4(sa->sa_bustag, write0, 0,
  90. (sc->sc_key << 24) | XAC_CTL1_OFFSET |
  91. XBOX_CTL1_CSIE | XBOX_CTL1_TRANSPARENT);
  92. bus_space_write_4(sa->sa_bustag, write0, 0,
  93. (sc->sc_key << 24) | XBC_CTL1_OFFSET |
  94. XBOX_CTL1_XSIE | XBOX_CTL1_XSBRE | XBOX_CTL1_XSSE);
  95. DELAY(100);
  96. bus_space_unmap(sa->sa_bustag, write0, sa->sa_reg[0].sbr_size);
  97. printf("\n");
  98. if (xbox_fix_range(sc, (struct sbus_softc *)parent) != 0)
  99. return;
  100. bzero(&xa, sizeof xa);
  101. xa.xa_name = "sbus";
  102. xa.xa_node = node;
  103. xa.xa_bustag = sa->sa_bustag;
  104. xa.xa_dmatag = sa->sa_dmatag;
  105. (void)config_found(&sc->sc_dev, (void *)&xa, xboxprint);
  106. }
  107. /*
  108. * Fix up our address ranges based on parent address spaces.
  109. */
  110. int
  111. xbox_fix_range(struct xbox_softc *sc, struct sbus_softc *sbp)
  112. {
  113. int error, i, j;
  114. error = getprop(sc->sc_node, "ranges", sizeof(struct sbus_range),
  115. &sc->sc_nrange, (void **)&sc->sc_range);
  116. if (error != 0) {
  117. printf("%s: PROM ranges too large\n", sc->sc_dev.dv_xname);
  118. return (error);
  119. }
  120. for (i = 0; i < sc->sc_nrange; i++) {
  121. for (j = 0; j < sbp->sc_nrange; j++) {
  122. if (sc->sc_range[i].pspace == sbp->sc_range[j].cspace) {
  123. sc->sc_range[i].poffset +=
  124. sbp->sc_range[j].poffset;
  125. sc->sc_range[i].pspace =
  126. sbp->sc_range[j].pspace;
  127. break;
  128. }
  129. }
  130. }
  131. return (0);
  132. }
  133. int
  134. xboxprint(void *args, const char *bus)
  135. {
  136. struct xbox_attach_args *xa = args;
  137. if (bus != NULL)
  138. printf("%s at %s", xa->xa_name, bus);
  139. return (UNCONF);
  140. }