isapnp_machdep.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* $OpenBSD: isapnp_machdep.c,v 1.4 2008/06/26 05:42:11 ray Exp $ */
  2. /* $NetBSD: isapnp_machdep.c,v 1.5 1997/10/04 17:32:30 thorpej Exp $ */
  3. /*-
  4. * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
  9. * NASA Ames Research Center.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  24. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /*
  33. * Copyright (c) 1996 Christos Zoulas. All rights reserved.
  34. *
  35. * Redistribution and use in source and binary forms, with or without
  36. * modification, are permitted provided that the following conditions
  37. * are met:
  38. * 1. Redistributions of source code must retain the above copyright
  39. * notice, this list of conditions and the following disclaimer.
  40. * 2. Redistributions in binary form must reproduce the above copyright
  41. * notice, this list of conditions and the following disclaimer in the
  42. * documentation and/or other materials provided with the distribution.
  43. * 3. All advertising materials mentioning features or use of this software
  44. * must display the following acknowledgement:
  45. * This product includes software developed by Christos Zoulas.
  46. * 4. The name of the author may not be used to endorse or promote products
  47. * derived from this software without specific prior written permission.
  48. *
  49. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  50. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  51. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  52. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  53. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  54. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  55. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  56. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  57. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  58. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. */
  60. /*
  61. * Machine-dependent portions of ISA PnP bus autoconfiguration.
  62. *
  63. * N.B. This file exists mostly to get around some lameness surrounding
  64. * the PnP spec. ISA PnP registers live where some `normal' ISA
  65. * devices do, but are e.g. write-only registers where the normal
  66. * device has a read-only register. This breaks in the presence of
  67. * i/o port accounting. This file takes care of mapping ISA PnP
  68. * registers without actually allocating them in extent maps.
  69. *
  70. * Since this is a machine-dependent file, we make all sorts of
  71. * assumptions about bus.h's guts. Beware!
  72. */
  73. #include <sys/param.h>
  74. #include <sys/systm.h>
  75. #include <sys/device.h>
  76. #include <sys/malloc.h>
  77. #include <machine/bus.h>
  78. #include <dev/isa/isapnpreg.h>
  79. #include <dev/isa/isavar.h>
  80. /* isapnp_map():
  81. * Map I/O regions used by PnP
  82. */
  83. int
  84. isapnp_map(struct isapnp_softc *sc)
  85. {
  86. #ifdef DIAGNOSTIC
  87. if (sc->sc_iot != I386_BUS_SPACE_IO)
  88. panic("isapnp_map: bogus bus space tag");
  89. #endif
  90. sc->sc_addr_ioh = ISAPNP_ADDR;
  91. sc->sc_wrdata_ioh = ISAPNP_WRDATA;
  92. return (0);
  93. }
  94. /* isapnp_unmap():
  95. * Unmap I/O regions used by PnP
  96. */
  97. void
  98. isapnp_unmap(struct isapnp_softc *sc)
  99. {
  100. /* Do nothing. */
  101. }
  102. /* isapnp_map_readport():
  103. * Called to map the PnP `read port', which is mapped independently
  104. * of the `write' and `addr' ports.
  105. *
  106. * NOTE: assumes the caller has filled in sc->sc_read_port!
  107. */
  108. int
  109. isapnp_map_readport(struct isapnp_softc *sc)
  110. {
  111. #ifdef _KERNEL
  112. int error;
  113. #endif
  114. #ifdef DIAGNOSTIC
  115. if (sc->sc_iot != I386_BUS_SPACE_IO)
  116. panic("isapnp_map_readport: bogus bus space tag");
  117. #endif
  118. #ifdef _KERNEL
  119. /* Check if some other device has already claimed this port. */
  120. if ((error = bus_space_map(sc->sc_iot, sc->sc_read_port, 1, 0,
  121. &sc->sc_read_ioh)) != 0)
  122. return error;
  123. /*
  124. * XXX: We unmap the port because it can and will be used by other
  125. * devices such as a joystick. We need a better port accounting
  126. * scheme with read and write ports.
  127. */
  128. bus_space_unmap(sc->sc_iot, sc->sc_read_ioh, 1);
  129. #endif
  130. return 0;
  131. }
  132. /* isapnp_unmap_readport():
  133. * Pretend to unmap a previously mapped `read port'.
  134. */
  135. void
  136. isapnp_unmap_readport(struct isapnp_softc *sc)
  137. {
  138. /* Do nothing */
  139. }