lebuffer.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* $OpenBSD: lebuffer.c,v 1.10 2012/12/05 23:20:21 deraadt Exp $ */
  2. /* $NetBSD: lebuffer.c,v 1.12 2002/03/11 16:00:57 pk Exp $ */
  3. /*-
  4. * Copyright (c) 1998 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Paul Kranenburg.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  23. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <sys/param.h>
  32. #include <sys/systm.h>
  33. #include <sys/kernel.h>
  34. #include <sys/errno.h>
  35. #include <sys/device.h>
  36. #include <sys/malloc.h>
  37. #include <machine/bus.h>
  38. #include <machine/autoconf.h>
  39. #include <machine/cpu.h>
  40. #include <dev/sbus/sbusvar.h>
  41. #include <dev/sbus/lebuffervar.h>
  42. int lebufprint(void *, const char *);
  43. int lebufmatch(struct device *, void *, void *);
  44. void lebufattach(struct device *, struct device *, void *);
  45. struct cfattach lebuffer_ca = {
  46. sizeof(struct lebuf_softc), lebufmatch, lebufattach
  47. };
  48. int
  49. lebufprint(void *aux, const char *busname)
  50. {
  51. struct sbus_attach_args *sa = aux;
  52. bus_space_tag_t t = sa->sa_bustag;
  53. struct lebuf_softc *sc = t->cookie;
  54. sa->sa_bustag = sc->sc_bustag; /* XXX */
  55. sbus_print(aux, busname); /* XXX */
  56. sa->sa_bustag = t; /* XXX */
  57. return (UNCONF);
  58. }
  59. int
  60. lebufmatch(struct device *parent, void *vcf, void *aux)
  61. {
  62. struct sbus_attach_args *sa = aux;
  63. struct cfdata *cf = vcf;
  64. return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
  65. }
  66. /*
  67. * Attach all the sub-devices we can find
  68. */
  69. void
  70. lebufattach(struct device *parent, struct device *self, void *aux)
  71. {
  72. struct sbus_attach_args *sa = aux;
  73. struct lebuf_softc *sc = (void *)self;
  74. int node;
  75. int sbusburst;
  76. struct sparc_bus_space_tag *sbt;
  77. bus_space_handle_t bh;
  78. sc->sc_bustag = sa->sa_bustag;
  79. sc->sc_dmatag = sa->sa_dmatag;
  80. if (sbus_bus_map(sa->sa_bustag,
  81. sa->sa_slot, sa->sa_offset, sa->sa_size,
  82. BUS_SPACE_MAP_LINEAR, 0, &bh) != 0) {
  83. printf("%s: attach: cannot map registers\n", self->dv_xname);
  84. return;
  85. }
  86. /*
  87. * This device's "register space" is just a buffer where the
  88. * Lance ring-buffers can be stored. Note the buffer's location
  89. * and size, so the `le' driver can pick them up.
  90. */
  91. sc->sc_buffer = (void *)bus_space_vaddr(sa->sa_bustag, bh);
  92. sc->sc_bufsiz = sa->sa_size;
  93. node = sc->sc_node = sa->sa_node;
  94. /*
  95. * Get transfer burst size from PROM
  96. */
  97. sbusburst = ((struct sbus_softc *)parent)->sc_burst;
  98. if (sbusburst == 0)
  99. sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
  100. sc->sc_burst = getpropint(node, "burst-sizes", -1);
  101. if (sc->sc_burst == -1)
  102. /* take SBus burst sizes */
  103. sc->sc_burst = sbusburst;
  104. /* Clamp at parent's burst sizes */
  105. sc->sc_burst &= sbusburst;
  106. /* Allocate a bus tag */
  107. sbt = malloc(sizeof(*sbt), M_DEVBUF, M_NOWAIT | M_ZERO);
  108. if (sbt == NULL) {
  109. printf("%s: attach: out of memory\n", self->dv_xname);
  110. return;
  111. }
  112. printf(": %dK memory\n", sc->sc_bufsiz / 1024);
  113. sbt->cookie = sc;
  114. sbt->parent = sc->sc_bustag;
  115. sbt->asi = sbt->parent->asi;
  116. sbt->sasi = sbt->parent->sasi;
  117. /* search through children */
  118. for (node = firstchild(node); node; node = nextsibling(node)) {
  119. struct sbus_attach_args sa;
  120. sbus_setup_attach_args((struct sbus_softc *)parent,
  121. sbt, sc->sc_dmatag, node, &sa);
  122. (void)config_found(&sc->sc_dev, (void *)&sa, lebufprint);
  123. sbus_destroy_attach_args(&sa);
  124. }
  125. }