lamebus.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  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. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _LAMEBUS_H_
  30. #define _LAMEBUS_H_
  31. #include <cpu.h>
  32. #include <spinlock.h>
  33. /*
  34. * Linear Always Mapped Extents
  35. *
  36. * Machine-independent definitions.
  37. */
  38. /* Vendors */
  39. #define LB_VENDOR_CS161 1
  40. /* CS161 devices */
  41. #define LBCS161_BUSCTL 1
  42. #define LBCS161_TIMER 2
  43. #define LBCS161_DISK 3
  44. #define LBCS161_SERIAL 4
  45. #define LBCS161_SCREEN 5
  46. #define LBCS161_NET 6
  47. #define LBCS161_EMUFS 7
  48. #define LBCS161_TRACE 8
  49. #define LBCS161_RANDOM 9
  50. /* LAMEbus controller always goes in slot 31 */
  51. #define LB_CONTROLLER_SLOT 31
  52. /* Number of slots */
  53. #define LB_NSLOTS 32
  54. /* LAMEbus controller per-slot config space */
  55. #define LB_CONFIG_SIZE 1024
  56. /* LAMEbus controller per-cpu control space */
  57. #define LB_CTLCPU_SIZE 1024
  58. /* LAMEbus controller slot offset to per-cpu control space */
  59. #define LB_CTLCPU_OFFSET 32768
  60. /* LAMEbus mapping size per slot */
  61. #define LB_SLOT_SIZE 65536
  62. /* Pointer to kind of function called on interrupt */
  63. typedef void (*lb_irqfunc)(void *devdata);
  64. /*
  65. * Driver data
  66. */
  67. struct lamebus_softc {
  68. struct spinlock ls_lock;
  69. /* Accessed from interrupts; synchronized with ls_lock */
  70. uint32_t ls_slotsinuse;
  71. void *ls_devdata[LB_NSLOTS];
  72. lb_irqfunc ls_irqfuncs[LB_NSLOTS];
  73. };
  74. /*
  75. * Allocate and set up a lamebus_softc for the system.
  76. */
  77. struct lamebus_softc *lamebus_init(void);
  78. /*
  79. * Search for and create cpu structures for the CPUs on the mainboard.
  80. */
  81. void lamebus_find_cpus(struct lamebus_softc *lamebus);
  82. /*
  83. * Start up secondary CPUs.
  84. */
  85. void lamebus_start_cpus(struct lamebus_softc *lamebus);
  86. /*
  87. * Look for a not-in-use slot containing a device whose vendor and device
  88. * ids match those provided, and whose version is in the range between
  89. * lowver and highver, inclusive.
  90. *
  91. * Returns a slot number (0-31) or -1 if no such device is found.
  92. */
  93. int lamebus_probe(struct lamebus_softc *,
  94. uint32_t vendorid, uint32_t deviceid,
  95. uint32_t lowver, uint32_t highver);
  96. /*
  97. * Mark a slot in-use (that is, has a device driver attached to it),
  98. * or unmark it. It is a fatal error to mark a slot that is already
  99. * in use, or unmark a slot that is not in use.
  100. */
  101. void lamebus_mark(struct lamebus_softc *, int slot);
  102. void lamebus_unmark(struct lamebus_softc *, int slot);
  103. /*
  104. * Attach to an interrupt.
  105. */
  106. void lamebus_attach_interrupt(struct lamebus_softc *, int slot,
  107. void *devdata,
  108. void (*irqfunc)(void *devdata));
  109. /*
  110. * Detach from interrupt.
  111. */
  112. void lamebus_detach_interrupt(struct lamebus_softc *, int slot);
  113. /*
  114. * Mask/unmask an interrupt.
  115. */
  116. void lamebus_mask_interrupt(struct lamebus_softc *, int slot);
  117. void lamebus_unmask_interrupt(struct lamebus_softc *, int slot);
  118. /*
  119. * Function to call to handle a LAMEbus interrupt.
  120. */
  121. void lamebus_interrupt(struct lamebus_softc *);
  122. /*
  123. * Have the LAMEbus controller power the system off.
  124. */
  125. void lamebus_poweroff(struct lamebus_softc *);
  126. /*
  127. * Ask the bus controller how much memory we have.
  128. */
  129. size_t lamebus_ramsize(void);
  130. /*
  131. * Turn on or off the inter-processor interrupt line to a CPU.
  132. */
  133. void lamebus_assert_ipi(struct lamebus_softc *, struct cpu *targetcpu);
  134. void lamebus_clear_ipi(struct lamebus_softc *, struct cpu *targetcpu);
  135. /*
  136. * Read/write 32-bit register at offset OFFSET within slot SLOT.
  137. * (Machine dependent.)
  138. */
  139. uint32_t lamebus_read_register(struct lamebus_softc *, int slot,
  140. uint32_t offset);
  141. void lamebus_write_register(struct lamebus_softc *, int slot,
  142. uint32_t offset, uint32_t val);
  143. /*
  144. * Map a buffer that starts at offset OFFSET within slot SLOT.
  145. */
  146. void *lamebus_map_area(struct lamebus_softc *, int slot,
  147. uint32_t offset);
  148. #endif /* _LAMEBUS_H_ */